aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pretzel.yyz.us>2005-06-26 17:11:03 -0400
committerJeff Garzik <jgarzik@pobox.com>2005-06-26 17:11:03 -0400
commit8b0ee07e108b2eefdab5bb73f33223f18926c3b2 (patch)
treef68ca04180c5488301a40ec212ef2eb2467cf56c /drivers/media
parent4638aef40ba9ebb9734caeed1f373c24015259fd (diff)
parent8678887e7fb43cd6c9be6c9807b05e77848e0920 (diff)
Merge upstream (approx. 2.6.12-git8) into 'janitor' branch of netdev-2.6.
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/common/ir-common.c72
-rw-r--r--drivers/media/common/saa7146_core.c4
-rw-r--r--drivers/media/common/saa7146_fops.c2
-rw-r--r--drivers/media/dvb/Kconfig4
-rw-r--r--drivers/media/dvb/Makefile2
-rw-r--r--drivers/media/dvb/b2c2/Kconfig51
-rw-r--r--drivers/media/dvb/b2c2/Makefile12
-rw-r--r--drivers/media/dvb/b2c2/b2c2-common.c214
-rw-r--r--drivers/media/dvb/b2c2/b2c2-usb-core.c549
-rw-r--r--drivers/media/dvb/b2c2/flexcop-common.h164
-rw-r--r--drivers/media/dvb/b2c2/flexcop-dma.c149
-rw-r--r--drivers/media/dvb/b2c2/flexcop-eeprom.c153
-rw-r--r--drivers/media/dvb/b2c2/flexcop-fe-tuner.c413
-rw-r--r--drivers/media/dvb/b2c2/flexcop-hw-filter.c204
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c210
-rw-r--r--drivers/media/dvb/b2c2/flexcop-misc.c67
-rw-r--r--drivers/media/dvb/b2c2/flexcop-pci.c381
-rw-r--r--drivers/media/dvb/b2c2/flexcop-reg.h702
-rw-r--r--drivers/media/dvb/b2c2/flexcop-sram.c403
-rw-r--r--drivers/media/dvb/b2c2/flexcop-usb.c577
-rw-r--r--drivers/media/dvb/b2c2/flexcop-usb.h119
-rw-r--r--drivers/media/dvb/b2c2/flexcop.c286
-rw-r--r--drivers/media/dvb/b2c2/flexcop.h30
-rw-r--r--drivers/media/dvb/b2c2/skystar2.c20
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig3
-rw-r--r--drivers/media/dvb/bt8xx/Makefile4
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c54
-rw-r--r--drivers/media/dvb/bt8xx/bt878.h6
-rw-r--r--drivers/media/dvb/bt8xx/dst.c969
-rw-r--r--drivers/media/dvb/bt8xx/dst.h40
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c861
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.h58
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h153
-rw-r--r--drivers/media/dvb/bt8xx/dst_priv.h1
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c121
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.h4
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c12
-rw-r--r--drivers/media/dvb/dibusb/Kconfig62
-rw-r--r--drivers/media/dvb/dibusb/Makefile11
-rw-r--r--drivers/media/dvb/dibusb/dvb-dibusb-core.c558
-rw-r--r--drivers/media/dvb/dibusb/dvb-dibusb-dvb.c185
-rw-r--r--drivers/media/dvb/dibusb/dvb-dibusb-fe-i2c.c582
-rw-r--r--drivers/media/dvb/dibusb/dvb-dibusb-firmware.c87
-rw-r--r--drivers/media/dvb/dibusb/dvb-dibusb-remote.c316
-rw-r--r--drivers/media/dvb/dibusb/dvb-dibusb-usb.c303
-rw-r--r--drivers/media/dvb/dibusb/dvb-dibusb.h327
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c32
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c38
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c43
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c75
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c22
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.h2
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig99
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile30
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c176
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c272
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c316
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c116
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb.h122
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c282
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.h65
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u-fe.c (renamed from drivers/media/dvb/dibusb/dvb-fe-dtt200u.c)113
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c171
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.h66
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-common.h44
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-dvb.c210
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-firmware.c100
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-i2c.c118
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h83
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c211
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c175
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-urb.c211
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h315
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c236
-rw-r--r--drivers/media/dvb/dvb-usb/umt-010.c162
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045-fe.c196
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c263
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.h78
-rw-r--r--drivers/media/dvb/frontends/Kconfig30
-rw-r--r--drivers/media/dvb/frontends/Makefile1
-rw-r--r--drivers/media/dvb/frontends/at76c651.c18
-rw-r--r--drivers/media/dvb/frontends/bcm3510.c853
-rw-r--r--drivers/media/dvb/frontends/bcm3510.h40
-rw-r--r--drivers/media/dvb/frontends/bcm3510_priv.h460
-rw-r--r--drivers/media/dvb/frontends/cx22700.c20
-rw-r--r--drivers/media/dvb/frontends/cx22702.c20
-rw-r--r--drivers/media/dvb/frontends/cx24110.c31
-rw-r--r--drivers/media/dvb/frontends/dib3000-common.c2
-rw-r--r--drivers/media/dvb/frontends/dib3000.h5
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c46
-rw-r--r--drivers/media/dvb/frontends/dib3000mb_priv.h2
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c53
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c94
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.h19
-rw-r--r--drivers/media/dvb/frontends/dvb_dummy_fe.c8
-rw-r--r--drivers/media/dvb/frontends/l64781.c22
-rw-r--r--drivers/media/dvb/frontends/mt312.c32
-rw-r--r--drivers/media/dvb/frontends/mt352.c40
-rw-r--r--drivers/media/dvb/frontends/mt352.h7
-rw-r--r--drivers/media/dvb/frontends/nxt2002.c22
-rw-r--r--drivers/media/dvb/frontends/nxt6000.c56
-rw-r--r--drivers/media/dvb/frontends/nxt6000_priv.h21
-rw-r--r--drivers/media/dvb/frontends/or51132.c14
-rw-r--r--drivers/media/dvb/frontends/sp8870.c20
-rw-r--r--drivers/media/dvb/frontends/sp887x.c22
-rw-r--r--drivers/media/dvb/frontends/stv0297.c24
-rw-r--r--drivers/media/dvb/frontends/stv0299.c114
-rw-r--r--drivers/media/dvb/frontends/tda10021.c22
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c284
-rw-r--r--drivers/media/dvb/frontends/tda1004x.h7
-rw-r--r--drivers/media/dvb/frontends/tda8083.c26
-rw-r--r--drivers/media/dvb/frontends/tda80xx.c36
-rw-r--r--drivers/media/dvb/frontends/ves1820.c23
-rw-r--r--drivers/media/dvb/frontends/ves1x93.c24
-rw-r--r--drivers/media/dvb/ttpci/av7110.c144
-rw-r--r--drivers/media/dvb/ttpci/av7110.h3
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c12
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.c4
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c20
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.h5
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c2
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c16
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c226
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c6
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c12
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c4
-rw-r--r--drivers/media/dvb/ttpci/budget.c4
-rw-r--r--drivers/media/dvb/ttpci/budget.h5
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c22
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c28
-rw-r--r--drivers/media/video/Kconfig15
-rw-r--r--drivers/media/video/adv7170.c16
-rw-r--r--drivers/media/video/adv7175.c16
-rw-r--r--drivers/media/video/bt819.c16
-rw-r--r--drivers/media/video/bt832.c50
-rw-r--r--drivers/media/video/bt832.h36
-rw-r--r--drivers/media/video/bt856.c16
-rw-r--r--drivers/media/video/bttv-cards.c101
-rw-r--r--drivers/media/video/bttv-driver.c2
-rw-r--r--drivers/media/video/bttv-i2c.c5
-rw-r--r--drivers/media/video/bttv.h3
-rw-r--r--drivers/media/video/bttvp.h8
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c488
-rw-r--r--drivers/media/video/cx88/cx88-cards.c230
-rw-r--r--drivers/media/video/cx88/cx88-core.c28
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c2
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c18
-rw-r--r--drivers/media/video/cx88/cx88-input.c11
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c52
-rw-r--r--drivers/media/video/cx88/cx88-reg.h3
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c103
-rw-r--r--drivers/media/video/cx88/cx88-vbi.c6
-rw-r--r--drivers/media/video/cx88/cx88-video.c59
-rw-r--r--drivers/media/video/cx88/cx88.h22
-rw-r--r--drivers/media/video/ir-kbd-gpio.c34
-rw-r--r--drivers/media/video/msp3400.c12
-rw-r--r--drivers/media/video/msp3400.h4
-rw-r--r--drivers/media/video/saa5246a.c1
-rw-r--r--drivers/media/video/saa5249.c1
-rw-r--r--drivers/media/video/saa7110.c16
-rw-r--r--drivers/media/video/saa7111.c16
-rw-r--r--drivers/media/video/saa7114.c16
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c21
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c163
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c112
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c16
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c21
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c14
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c92
-rw-r--r--drivers/media/video/saa7134/saa7134.h17
-rw-r--r--drivers/media/video/saa7185.c16
-rw-r--r--drivers/media/video/tda7432.c1
-rw-r--r--drivers/media/video/tda9840.c1
-rw-r--r--drivers/media/video/tda9875.c1
-rw-r--r--drivers/media/video/tda9887.c41
-rw-r--r--drivers/media/video/tea6415c.c1
-rw-r--r--drivers/media/video/tea6420.c1
-rw-r--r--drivers/media/video/tuner-3036.c17
-rw-r--r--drivers/media/video/tuner-core.c205
-rw-r--r--drivers/media/video/tuner-simple.c53
-rw-r--r--drivers/media/video/tvaudio.c24
-rw-r--r--drivers/media/video/tveeprom.c3
-rw-r--r--drivers/media/video/tvmixer.c4
-rw-r--r--drivers/media/video/v4l1-compat.c10
-rw-r--r--drivers/media/video/video-buf-dvb.c15
-rw-r--r--drivers/media/video/vpx3220.c16
190 files changed, 14093 insertions, 5170 deletions
diff --git a/drivers/media/common/ir-common.c b/drivers/media/common/ir-common.c
index 84a49d2ec919..4adb2843f8be 100644
--- a/drivers/media/common/ir-common.c
+++ b/drivers/media/common/ir-common.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ir-common.c,v 1.8 2005/02/22 12:28:40 kraxel Exp $ 2 * $Id: ir-common.c,v 1.10 2005/05/22 19:23:39 nsh Exp $
3 * 3 *
4 * some common structs and functions to handle infrared remotes via 4 * some common structs and functions to handle infrared remotes via
5 * input layer ... 5 * input layer ...
@@ -131,10 +131,10 @@ IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
131 [ 18 ] = KEY_KP0, 131 [ 18 ] = KEY_KP0,
132 132
133 [ 0 ] = KEY_POWER, 133 [ 0 ] = KEY_POWER,
134 [ 27 ] = KEY_LANGUAGE, //MTS button 134// [ 27 ] = MTS button
135 [ 2 ] = KEY_TUNER, // TV/FM 135 [ 2 ] = KEY_TUNER, // TV/FM
136 [ 30 ] = KEY_VIDEO, 136 [ 30 ] = KEY_VIDEO,
137 [ 22 ] = KEY_INFO, //display button 137// [ 22 ] = display button
138 [ 4 ] = KEY_VOLUMEUP, 138 [ 4 ] = KEY_VOLUMEUP,
139 [ 8 ] = KEY_VOLUMEDOWN, 139 [ 8 ] = KEY_VOLUMEDOWN,
140 [ 12 ] = KEY_CHANNELUP, 140 [ 12 ] = KEY_CHANNELUP,
@@ -142,7 +142,7 @@ IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
142 [ 3 ] = KEY_ZOOM, // fullscreen 142 [ 3 ] = KEY_ZOOM, // fullscreen
143 [ 31 ] = KEY_SUBTITLE, // closed caption/teletext 143 [ 31 ] = KEY_SUBTITLE, // closed caption/teletext
144 [ 32 ] = KEY_SLEEP, 144 [ 32 ] = KEY_SLEEP,
145 [ 41 ] = KEY_SEARCH, //boss key 145// [ 41 ] = boss key
146 [ 20 ] = KEY_MUTE, 146 [ 20 ] = KEY_MUTE,
147 [ 43 ] = KEY_RED, 147 [ 43 ] = KEY_RED,
148 [ 44 ] = KEY_GREEN, 148 [ 44 ] = KEY_GREEN,
@@ -150,17 +150,17 @@ IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
150 [ 46 ] = KEY_BLUE, 150 [ 46 ] = KEY_BLUE,
151 [ 24 ] = KEY_KPPLUS, //fine tune + 151 [ 24 ] = KEY_KPPLUS, //fine tune +
152 [ 25 ] = KEY_KPMINUS, //fine tune - 152 [ 25 ] = KEY_KPMINUS, //fine tune -
153 [ 42 ] = KEY_ANGLE, //picture in picture 153// [ 42 ] = picture in picture
154 [ 33 ] = KEY_KPDOT, 154 [ 33 ] = KEY_KPDOT,
155 [ 19 ] = KEY_KPENTER, 155 [ 19 ] = KEY_KPENTER,
156 [ 17 ] = KEY_AGAIN, //recall 156// [ 17 ] = recall
157 [ 34 ] = KEY_BACK, 157 [ 34 ] = KEY_BACK,
158 [ 35 ] = KEY_PLAYPAUSE, 158 [ 35 ] = KEY_PLAYPAUSE,
159 [ 36 ] = KEY_NEXT, 159 [ 36 ] = KEY_NEXT,
160 [ 37 ] = KEY_T, //time shifting 160// [ 37 ] = time shifting
161 [ 38 ] = KEY_STOP, 161 [ 38 ] = KEY_STOP,
162 [ 39 ] = KEY_RECORD, 162 [ 39 ] = KEY_RECORD
163 [ 40 ] = KEY_SHUFFLE //snapshot 163// [ 40 ] = snapshot
164}; 164};
165EXPORT_SYMBOL_GPL(ir_codes_winfast); 165EXPORT_SYMBOL_GPL(ir_codes_winfast);
166 166
@@ -184,18 +184,30 @@ IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = {
184 [ 0x07 ] = KEY_KP7, // 7 184 [ 0x07 ] = KEY_KP7, // 7
185 [ 0x08 ] = KEY_KP8, // 8 185 [ 0x08 ] = KEY_KP8, // 8
186 [ 0x09 ] = KEY_KP9, // 9 186 [ 0x09 ] = KEY_KP9, // 9
187 [ 0x0a ] = KEY_TEXT, // keypad asterisk as well
187 [ 0x0b ] = KEY_RED, // red button 188 [ 0x0b ] = KEY_RED, // red button
188 [ 0x0c ] = KEY_OPTION, // black key without text 189 [ 0x0c ] = KEY_RADIO, // radio
189 [ 0x0d ] = KEY_MENU, // menu 190 [ 0x0d ] = KEY_MENU, // menu
191 [ 0x0e ] = KEY_SUBTITLE, // also the # key
190 [ 0x0f ] = KEY_MUTE, // mute 192 [ 0x0f ] = KEY_MUTE, // mute
191 [ 0x10 ] = KEY_VOLUMEUP, // volume + 193 [ 0x10 ] = KEY_VOLUMEUP, // volume +
192 [ 0x11 ] = KEY_VOLUMEDOWN, // volume - 194 [ 0x11 ] = KEY_VOLUMEDOWN, // volume -
193 [ 0x1e ] = KEY_NEXT, // skip >| 195 [ 0x12 ] = KEY_PREVIOUS, // previous channel
196 [ 0x14 ] = KEY_UP, // up
197 [ 0x15 ] = KEY_DOWN, // down
198 [ 0x16 ] = KEY_LEFT, // left
199 [ 0x17 ] = KEY_RIGHT, // right
200 [ 0x18 ] = KEY_VIDEO, // Videos
201 [ 0x19 ] = KEY_AUDIO, // Music
202 [ 0x1a ] = KEY_MHP, // Pictures - presume this means "Multimedia Home Platform"- no "PICTURES" key in input.h
203 [ 0x1b ] = KEY_EPG, // Guide
204 [ 0x1c ] = KEY_TV, // TV
205 [ 0x1e ] = KEY_NEXTSONG, // skip >|
194 [ 0x1f ] = KEY_EXIT, // back/exit 206 [ 0x1f ] = KEY_EXIT, // back/exit
195 [ 0x20 ] = KEY_CHANNELUP, // channel / program + 207 [ 0x20 ] = KEY_CHANNELUP, // channel / program +
196 [ 0x21 ] = KEY_CHANNELDOWN, // channel / program - 208 [ 0x21 ] = KEY_CHANNELDOWN, // channel / program -
197 [ 0x22 ] = KEY_CHANNEL, // source (old black remote) 209 [ 0x22 ] = KEY_CHANNEL, // source (old black remote)
198 [ 0x24 ] = KEY_PREVIOUS, // replay |< 210 [ 0x24 ] = KEY_PREVIOUSSONG, // replay |<
199 [ 0x25 ] = KEY_ENTER, // OK 211 [ 0x25 ] = KEY_ENTER, // OK
200 [ 0x26 ] = KEY_SLEEP, // minimize (old black remote) 212 [ 0x26 ] = KEY_SLEEP, // minimize (old black remote)
201 [ 0x29 ] = KEY_BLUE, // blue key 213 [ 0x29 ] = KEY_BLUE, // blue key
@@ -213,6 +225,39 @@ IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = {
213}; 225};
214EXPORT_SYMBOL(ir_codes_hauppauge_new); 226EXPORT_SYMBOL(ir_codes_hauppauge_new);
215 227
228IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
229 [ 2 ] = KEY_KP0,
230 [ 1 ] = KEY_KP1,
231 [ 11 ] = KEY_KP2,
232 [ 27 ] = KEY_KP3,
233 [ 5 ] = KEY_KP4,
234 [ 9 ] = KEY_KP5,
235 [ 21 ] = KEY_KP6,
236 [ 6 ] = KEY_KP7,
237 [ 10 ] = KEY_KP8,
238 [ 18 ] = KEY_KP9,
239
240 [ 3 ] = KEY_TUNER, // TV/FM
241 [ 7 ] = KEY_SEARCH, // scan
242 [ 28 ] = KEY_ZOOM, // full screen
243 [ 30 ] = KEY_POWER,
244 [ 23 ] = KEY_VOLUMEDOWN,
245 [ 31 ] = KEY_VOLUMEUP,
246 [ 20 ] = KEY_CHANNELDOWN,
247 [ 22 ] = KEY_CHANNELUP,
248 [ 24 ] = KEY_MUTE,
249
250 [ 0 ] = KEY_LIST, // source
251 [ 19 ] = KEY_INFO, // loop
252 [ 16 ] = KEY_LAST, // +100
253 [ 13 ] = KEY_CLEAR, // reset
254 [ 12 ] = BTN_RIGHT, // fun++
255 [ 4 ] = BTN_LEFT, // fun--
256 [ 14 ] = KEY_GOTO, // function
257 [ 15 ] = KEY_STOP, // freeze
258};
259EXPORT_SYMBOL(ir_codes_pixelview);
260
216/* -------------------------------------------------------------------------- */ 261/* -------------------------------------------------------------------------- */
217 262
218static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir) 263static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)
@@ -379,3 +424,4 @@ EXPORT_SYMBOL_GPL(ir_decode_biphase);
379 * c-basic-offset: 8 424 * c-basic-offset: 8
380 * End: 425 * End:
381 */ 426 */
427
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index 9f6c19ac1285..50e8b8654018 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -23,9 +23,9 @@
23LIST_HEAD(saa7146_devices); 23LIST_HEAD(saa7146_devices);
24DECLARE_MUTEX(saa7146_devices_lock); 24DECLARE_MUTEX(saa7146_devices_lock);
25 25
26static int saa7146_num = 0; 26static int saa7146_num;
27 27
28unsigned int saa7146_debug = 0; 28unsigned int saa7146_debug;
29 29
30module_param(saa7146_debug, int, 0644); 30module_param(saa7146_debug, int, 0644);
31MODULE_PARM_DESC(saa7146_debug, "debug level (default: 0)"); 31MODULE_PARM_DESC(saa7146_debug, "debug level (default: 0)");
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index cb826c9adfe7..c04fd11526e0 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -403,7 +403,7 @@ static struct file_operations video_fops =
403 .llseek = no_llseek, 403 .llseek = no_llseek,
404}; 404};
405 405
406void vv_callback(struct saa7146_dev *dev, unsigned long status) 406static void vv_callback(struct saa7146_dev *dev, unsigned long status)
407{ 407{
408 u32 isr = status; 408 u32 isr = status;
409 409
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig
index 883ec08490f4..01387f883cdf 100644
--- a/drivers/media/dvb/Kconfig
+++ b/drivers/media/dvb/Kconfig
@@ -27,13 +27,13 @@ source "drivers/media/dvb/ttpci/Kconfig"
27 27
28comment "Supported USB Adapters" 28comment "Supported USB Adapters"
29 depends on DVB_CORE && USB 29 depends on DVB_CORE && USB
30source "drivers/media/dvb/dvb-usb/Kconfig"
30source "drivers/media/dvb/ttusb-budget/Kconfig" 31source "drivers/media/dvb/ttusb-budget/Kconfig"
31source "drivers/media/dvb/ttusb-dec/Kconfig" 32source "drivers/media/dvb/ttusb-dec/Kconfig"
32source "drivers/media/dvb/dibusb/Kconfig"
33source "drivers/media/dvb/cinergyT2/Kconfig" 33source "drivers/media/dvb/cinergyT2/Kconfig"
34 34
35comment "Supported FlexCopII (B2C2) Adapters" 35comment "Supported FlexCopII (B2C2) Adapters"
36 depends on DVB_CORE && PCI 36 depends on DVB_CORE && (PCI || USB)
37source "drivers/media/dvb/b2c2/Kconfig" 37source "drivers/media/dvb/b2c2/Kconfig"
38 38
39comment "Supported BT878 Adapters" 39comment "Supported BT878 Adapters"
diff --git a/drivers/media/dvb/Makefile b/drivers/media/dvb/Makefile
index 520fc3902819..3c6ff1619103 100644
--- a/drivers/media/dvb/Makefile
+++ b/drivers/media/dvb/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the kernel multimedia device drivers. 2# Makefile for the kernel multimedia device drivers.
3# 3#
4 4
5obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ dibusb/ cinergyT2/ 5obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ cinergyT2/ dvb-usb/
diff --git a/drivers/media/dvb/b2c2/Kconfig b/drivers/media/dvb/b2c2/Kconfig
index 52596907a0be..fafd0ab3a28f 100644
--- a/drivers/media/dvb/b2c2/Kconfig
+++ b/drivers/media/dvb/b2c2/Kconfig
@@ -1,26 +1,51 @@
1config DVB_B2C2_SKYSTAR 1config DVB_B2C2_FLEXCOP
2 tristate "B2C2/Technisat Air/Sky/CableStar 2 PCI" 2 tristate "Technisat/B2C2 FlexCopII(b) and FlexCopIII adapters"
3 depends on DVB_CORE && PCI 3 depends on DVB_CORE
4 select DVB_STV0299 4 select DVB_STV0299
5 select DVB_MT352 5 select DVB_MT352
6 select DVB_MT312 6 select DVB_MT312
7 select DVB_NXT2002 7 select DVB_NXT2002
8 select DVB_STV0297
9 select DVB_BCM3510
8 help 10 help
9 Support for the Skystar2 PCI DVB card by Technisat, which 11 Support for the digital TV receiver chip made by B2C2 Inc. included in
10 is equipped with the FlexCopII chipset by B2C2, and 12 Technisats PCI cards and USB boxes.
11 for the B2C2/BBTI Air2PC-ATSC card.
12 13
13 Say Y if you own such a device and want to use it. 14 Say Y if you own such a device and want to use it.
14 15
15config DVB_B2C2_USB 16config DVB_B2C2_FLEXCOP_PCI
16 tristate "B2C2/Technisat Air/Sky/Cable2PC USB" 17 tristate "Technisat/B2C2 Air/Sky/Cable2PC PCI"
17 depends on DVB_CORE && USB && EXPERIMENTAL 18 depends on DVB_B2C2_FLEXCOP && PCI
19 help
20 Support for the Air/Sky/CableStar2 PCI card (DVB/ATSC) by Technisat/B2C2.
21
22 Say Y if you own such a device and want to use it.
23
24config DVB_B2C2_FLEXCOP_USB
25 tristate "Technisat/B2C2 Air/Sky/Cable2PC USB"
26 depends on DVB_B2C2_FLEXCOP && USB
27 help
28 Support for the Air/Sky/Cable2PC USB1.1 box (DVB/ATSC) by Technisat/B2C2,
29
30 Say Y if you own such a device and want to use it.
31
32config DVB_B2C2_FLEXCOP_DEBUG
33 bool "Enable debug for the B2C2 FlexCop drivers"
34 depends on DVB_B2C2_FLEXCOP
35 help
36 Say Y if you want to enable the module option to control debug messages
37 of all B2C2 FlexCop drivers.
38
39config DVB_B2C2_SKYSTAR
40 tristate "B2C2/Technisat Air/Sky/CableStar 2 PCI"
41 depends on DVB_CORE && PCI
18 select DVB_STV0299 42 select DVB_STV0299
19 select DVB_MT352 43 select DVB_MT352
44 select DVB_MT312
45 select DVB_NXT2002
20 help 46 help
21 Support for the Air/Sky/Cable2PC USB DVB device by B2C2. Currently 47 Support for the Skystar2 PCI DVB card by Technisat, which
22 the does nothing, but providing basic function for the used usb 48 is equipped with the FlexCopII chipset by B2C2, and
23 protocol. 49 for the B2C2/BBTI Air2PC-ATSC card.
24 50
25 Say Y if you own such a device and want to use it. 51 Say Y if you own such a device and want to use it.
26
diff --git a/drivers/media/dvb/b2c2/Makefile b/drivers/media/dvb/b2c2/Makefile
index 9fb1247bfab8..7703812af34f 100644
--- a/drivers/media/dvb/b2c2/Makefile
+++ b/drivers/media/dvb/b2c2/Makefile
@@ -1,6 +1,14 @@
1obj-b2c2-usb = b2c2-usb-core.o b2c2-common.o 1b2c2-flexcop-objs = flexcop.o flexcop-fe-tuner.o flexcop-i2c.o \
2 flexcop-sram.o flexcop-eeprom.o flexcop-misc.o flexcop-hw-filter.o \
3 flexcop-dma.o
4obj-$(CONFIG_DVB_B2C2_FLEXCOP) += b2c2-flexcop.o
5
6b2c2-flexcop-pci-objs = flexcop-pci.o
7obj-$(CONFIG_DVB_B2C2_FLEXCOP_PCI) += b2c2-flexcop-pci.o
8
9b2c2-flexcop-usb-objs = flexcop-usb.o
10obj-$(CONFIG_DVB_B2C2_FLEXCOP_USB) += b2c2-flexcop-usb.o
2 11
3obj-$(CONFIG_DVB_B2C2_SKYSTAR) += skystar2.o 12obj-$(CONFIG_DVB_B2C2_SKYSTAR) += skystar2.o
4obj-$(CONFIG_DVB_B2C2_USB) + = b2c2-usb.o
5 13
6EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 14EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/b2c2/b2c2-common.c b/drivers/media/dvb/b2c2/b2c2-common.c
deleted file mode 100644
index 000d60c405e3..000000000000
--- a/drivers/media/dvb/b2c2/b2c2-common.c
+++ /dev/null
@@ -1,214 +0,0 @@
1/*
2 * b2c2-common.c - common methods for the B2C2/Technisat SkyStar2 PCI DVB card and
3 * for the B2C2/Technisat Sky/Cable/AirStar USB devices
4 * based on the FlexCopII/FlexCopIII by B2C2, Inc.
5 *
6 * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
7 *
8 * FIX: DISEQC Tone Burst in flexcop_diseqc_ioctl()
9 * FIX: FULL soft DiSEqC for skystar2 (FlexCopII rev 130) VP310 equipped
10 * Vincenzo Di Massa, hawk.it at tiscalinet.it
11 *
12 * Converted to Linux coding style
13 * Misc reorganization, polishing, restyling
14 * Roberto Ragusa, r.ragusa at libero.it
15 *
16 * Added hardware filtering support,
17 * Niklas Peinecke, peinecke at gdv.uni-hannover.de
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU Lesser General Public License
21 * as published by the Free Software Foundation; either version 2.1
22 * of the License, or (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 *
33 */
34#include "stv0299.h"
35#include "mt352.h"
36#include "mt312.h"
37
38static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
39{
40 u8 aclk = 0;
41 u8 bclk = 0;
42
43 if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
44 else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
45 else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
46 else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
47 else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
48 else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
49
50 stv0299_writereg (fe, 0x13, aclk);
51 stv0299_writereg (fe, 0x14, bclk);
52 stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
53 stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
54 stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
55
56 return 0;
57}
58
59static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
60{
61 u8 buf[4];
62 u32 div;
63 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
64// struct adapter* adapter = (struct adapter*) fe->dvb->priv;
65
66 div = params->frequency / 125;
67
68 buf[0] = (div >> 8) & 0x7f;
69 buf[1] = div & 0xff;
70 buf[2] = 0x84; // 0xC4
71 buf[3] = 0x08;
72
73 if (params->frequency < 1500000) buf[3] |= 0x10;
74
75// if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO;
76 return 0;
77}
78
79static u8 samsung_tbmu24112_inittab[] = {
80 0x01, 0x15,
81 0x02, 0x30,
82 0x03, 0x00,
83 0x04, 0x7D,
84 0x05, 0x35,
85 0x06, 0x02,
86 0x07, 0x00,
87 0x08, 0xC3,
88 0x0C, 0x00,
89 0x0D, 0x81,
90 0x0E, 0x23,
91 0x0F, 0x12,
92 0x10, 0x7E,
93 0x11, 0x84,
94 0x12, 0xB9,
95 0x13, 0x88,
96 0x14, 0x89,
97 0x15, 0xC9,
98 0x16, 0x00,
99 0x17, 0x5C,
100 0x18, 0x00,
101 0x19, 0x00,
102 0x1A, 0x00,
103 0x1C, 0x00,
104 0x1D, 0x00,
105 0x1E, 0x00,
106 0x1F, 0x3A,
107 0x20, 0x2E,
108 0x21, 0x80,
109 0x22, 0xFF,
110 0x23, 0xC1,
111 0x28, 0x00,
112 0x29, 0x1E,
113 0x2A, 0x14,
114 0x2B, 0x0F,
115 0x2C, 0x09,
116 0x2D, 0x05,
117 0x31, 0x1F,
118 0x32, 0x19,
119 0x33, 0xFE,
120 0x34, 0x93,
121 0xff, 0xff,
122};
123
124static struct stv0299_config samsung_tbmu24112_config = {
125 .demod_address = 0x68,
126 .inittab = samsung_tbmu24112_inittab,
127 .mclk = 88000000UL,
128 .invert = 0,
129 .enhanced_tuning = 0,
130 .skip_reinit = 0,
131 .lock_output = STV0229_LOCKOUTPUT_LK,
132 .volt13_op0_op1 = STV0299_VOLT13_OP1,
133 .min_delay_ms = 100,
134 .set_symbol_rate = samsung_tbmu24112_set_symbol_rate,
135 .pll_set = samsung_tbmu24112_pll_set,
136};
137
138
139
140
141
142static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
143{
144 static u8 mt352_clock_config [] = { 0x89, 0x10, 0x2d };
145 static u8 mt352_reset [] = { 0x50, 0x80 };
146 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
147 static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0xa1 };
148 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
149
150 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
151 udelay(2000);
152 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
153 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
154
155 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
156 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
157
158 return 0;
159}
160
161static int samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
162{
163 u32 div;
164 unsigned char bs = 0;
165
166 #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
167 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
168
169 if (params->frequency >= 48000000 && params->frequency <= 154000000) bs = 0x09;
170 if (params->frequency >= 161000000 && params->frequency <= 439000000) bs = 0x0a;
171 if (params->frequency >= 447000000 && params->frequency <= 863000000) bs = 0x08;
172
173 pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address
174 pllbuf[1] = div >> 8;
175 pllbuf[2] = div & 0xff;
176 pllbuf[3] = 0xcc;
177 pllbuf[4] = bs;
178
179 return 0;
180}
181
182static struct mt352_config samsung_tdtc9251dh0_config = {
183
184 .demod_address = 0x0f,
185 .demod_init = samsung_tdtc9251dh0_demod_init,
186 .pll_set = samsung_tdtc9251dh0_pll_set,
187};
188
189static int skystar23_samsung_tbdu18132_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
190{
191 u8 buf[4];
192 u32 div;
193 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
194// struct adapter* adapter = (struct adapter*) fe->dvb->priv;
195
196 div = (params->frequency + (125/2)) / 125;
197
198 buf[0] = (div >> 8) & 0x7f;
199 buf[1] = (div >> 0) & 0xff;
200 buf[2] = 0x84 | ((div >> 10) & 0x60);
201 buf[3] = 0x80;
202
203 if (params->frequency < 1550000)
204 buf[3] |= 0x02;
205
206 //if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO;
207 return 0;
208}
209
210static struct mt312_config skystar23_samsung_tbdu18132_config = {
211
212 .demod_address = 0x0e,
213 .pll_set = skystar23_samsung_tbdu18132_pll_set,
214};
diff --git a/drivers/media/dvb/b2c2/b2c2-usb-core.c b/drivers/media/dvb/b2c2/b2c2-usb-core.c
deleted file mode 100644
index 9306da046c91..000000000000
--- a/drivers/media/dvb/b2c2/b2c2-usb-core.c
+++ /dev/null
@@ -1,549 +0,0 @@
1/*
2 * Copyright (C) 2004 Patrick Boettcher <patrick.boettcher@desy.de>,
3 * Luca Bertagnolio <>,
4 *
5 * based on information provided by John Jurrius from BBTI, Inc.
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, version 2.
10 *
11 */
12
13#include <linux/config.h>
14#include <linux/kernel.h>
15#include <linux/usb.h>
16#include <linux/moduleparam.h>
17#include <linux/pci.h>
18#include <linux/version.h>
19
20#include "dmxdev.h"
21#include "dvb_demux.h"
22#include "dvb_filter.h"
23#include "dvb_net.h"
24#include "dvb_frontend.h"
25
26/* debug */
27#define dprintk(level,args...) \
28 do { if ((debug & level)) { printk(args); } } while (0)
29#define debug_dump(b,l) if (debug) {\
30 int i; deb_xfer("%s: %d > ",__FUNCTION__,l); \
31 for (i = 0; i < l; i++) deb_xfer("%02x ", b[i]); \
32 deb_xfer("\n");\
33}
34
35static int debug;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "set debugging level (1=info,ts=2,ctrl=4 (or-able)).");
38
39#define deb_info(args...) dprintk(0x01,args)
40#define deb_ts(args...) dprintk(0x02,args)
41#define deb_ctrl(args...) dprintk(0x04,args)
42
43/* Version information */
44#define DRIVER_VERSION "0.0"
45#define DRIVER_DESC "Driver for B2C2/Technisat Air/Cable/Sky-2-PC USB devices"
46#define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
47
48/* transfer parameters */
49#define B2C2_USB_FRAMES_PER_ISO 4
50#define B2C2_USB_NUM_ISO_URB 4 /* TODO check out a good value */
51
52#define B2C2_USB_CTRL_PIPE_IN usb_rcvctrlpipe(b2c2->udev,0)
53#define B2C2_USB_CTRL_PIPE_OUT usb_sndctrlpipe(b2c2->udev,0)
54#define B2C2_USB_DATA_PIPE usb_rcvisocpipe(b2c2->udev,0x81)
55
56struct usb_b2c2_usb {
57 struct usb_device *udev;
58 struct usb_interface *uintf;
59
60 u8 *iso_buffer;
61 int buffer_size;
62 dma_addr_t iso_dma_handle;
63 struct urb *iso_urb[B2C2_USB_NUM_ISO_URB];
64};
65
66
67/*
68 * USB
69 * 10 90 34 12 78 56 04 00
70 * usb_control_msg(udev, usb_sndctrlpipe(udev,0),
71 * 0x90,
72 * 0x10,
73 * 0x1234,
74 * 0x5678,
75 * buf,
76 * 4,
77 * 5*HZ);
78 *
79 * extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
80 * __u8 request,
81 * __u8 requesttype,
82 * __u16 value,
83 * __u16 index,
84 * void *data,
85 * __u16 size,
86 * int timeout);
87 *
88 */
89
90/* request types */
91typedef enum {
92
93/* something is wrong with this part
94 RTYPE_READ_DW = (1 << 6),
95 RTYPE_WRITE_DW_1 = (3 << 6),
96 RTYPE_READ_V8_MEMORY = (6 << 6),
97 RTYPE_WRITE_V8_MEMORY = (7 << 6),
98 RTYPE_WRITE_V8_FLASH = (8 << 6),
99 RTYPE_GENERIC = (9 << 6),
100*/
101 RTYPE_READ_DW = (3 << 6),
102 RTYPE_WRITE_DW_1 = (1 << 6),
103
104 RTYPE_READ_V8_MEMORY = (6 << 6),
105 RTYPE_WRITE_V8_MEMORY = (7 << 6),
106 RTYPE_WRITE_V8_FLASH = (8 << 6),
107 RTYPE_GENERIC = (9 << 6),
108} b2c2_usb_request_type_t;
109
110/* request */
111typedef enum {
112 B2C2_USB_WRITE_V8_MEM = 0x04,
113 B2C2_USB_READ_V8_MEM = 0x05,
114 B2C2_USB_READ_REG = 0x08,
115 B2C2_USB_WRITE_REG = 0x0A,
116/* B2C2_USB_WRITEREGLO = 0x0A, */
117 B2C2_USB_WRITEREGHI = 0x0B,
118 B2C2_USB_FLASH_BLOCK = 0x10,
119 B2C2_USB_I2C_REQUEST = 0x11,
120 B2C2_USB_UTILITY = 0x12,
121} b2c2_usb_request_t;
122
123/* function definition for I2C_REQUEST */
124typedef enum {
125 USB_FUNC_I2C_WRITE = 0x01,
126 USB_FUNC_I2C_MULTIWRITE = 0x02,
127 USB_FUNC_I2C_READ = 0x03,
128 USB_FUNC_I2C_REPEATWRITE = 0x04,
129 USB_FUNC_GET_DESCRIPTOR = 0x05,
130 USB_FUNC_I2C_REPEATREAD = 0x06,
131/* DKT 020208 - add this to support special case of DiSEqC */
132 USB_FUNC_I2C_CHECKWRITE = 0x07,
133 USB_FUNC_I2C_CHECKRESULT = 0x08,
134} b2c2_usb_i2c_function_t;
135
136/*
137 * function definition for UTILITY request 0x12
138 * DKT 020304 - new utility function
139 */
140typedef enum {
141 UTILITY_SET_FILTER = 0x01,
142 UTILITY_DATA_ENABLE = 0x02,
143 UTILITY_FLEX_MULTIWRITE = 0x03,
144 UTILITY_SET_BUFFER_SIZE = 0x04,
145 UTILITY_FLEX_OPERATOR = 0x05,
146 UTILITY_FLEX_RESET300_START = 0x06,
147 UTILITY_FLEX_RESET300_STOP = 0x07,
148 UTILITY_FLEX_RESET300 = 0x08,
149 UTILITY_SET_ISO_SIZE = 0x09,
150 UTILITY_DATA_RESET = 0x0A,
151 UTILITY_GET_DATA_STATUS = 0x10,
152 UTILITY_GET_V8_REG = 0x11,
153/* DKT 020326 - add function for v1.14 */
154 UTILITY_SRAM_WRITE = 0x12,
155 UTILITY_SRAM_READ = 0x13,
156 UTILITY_SRAM_TESTFILL = 0x14,
157 UTILITY_SRAM_TESTSET = 0x15,
158 UTILITY_SRAM_TESTVERIFY = 0x16,
159} b2c2_usb_utility_function_t;
160
161#define B2C2_WAIT_FOR_OPERATION_RW 1 // 1 s
162#define B2C2_WAIT_FOR_OPERATION_RDW 3 // 3 s
163#define B2C2_WAIT_FOR_OPERATION_WDW 1 // 1 s
164
165#define B2C2_WAIT_FOR_OPERATION_V8READ 3 // 3 s
166#define B2C2_WAIT_FOR_OPERATION_V8WRITE 3 // 3 s
167#define B2C2_WAIT_FOR_OPERATION_V8FLASH 3 // 3 s
168
169/* JLP 111700: we will include the 1 bit gap between the upper and lower 3 bits
170 * in the IBI address, to make the V8 code simpler.
171 * PCI ADDRESS FORMAT: 0x71C -> 0000 0111 0001 1100 (these are the six bits used)
172 * in general: 0000 0HHH 000L LL00
173 * IBI ADDRESS FORMAT: RHHH BLLL
174 *
175 * where R is the read(1)/write(0) bit, B is the busy bit
176 * and HHH and LLL are the two sets of three bits from the PCI address.
177 */
178#define B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(usPCI) (u8) (((usPCI >> 2) & 0x07) + ((usPCI >> 4) & 0x70))
179#define B2C2_FLEX_INTERNALADDR_TO_PCIOFFSET(ucAddr) (u16) (((ucAddr & 0x07) << 2) + ((ucAddr & 0x70) << 4))
180
181/*
182 * DKT 020228 - forget about this VENDOR_BUFFER_SIZE, read and write register
183 * deal with DWORD or 4 bytes, that should be should from now on
184 */
185static u32 b2c2_usb_read_dw(struct usb_b2c2_usb *b2c2, u16 wRegOffsPCI)
186{
187 u32 val;
188 u16 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) | 0x0080;
189 int len = usb_control_msg(b2c2->udev,
190 B2C2_USB_CTRL_PIPE_IN,
191 B2C2_USB_READ_REG,
192 RTYPE_READ_DW,
193 wAddress,
194 0,
195 &val,
196 sizeof(u32),
197 B2C2_WAIT_FOR_OPERATION_RDW * 1000);
198
199 if (len != sizeof(u32)) {
200 err("error while reading dword from %d (%d).",wAddress,wRegOffsPCI);
201 return -EIO;
202 } else
203 return val;
204}
205
206/*
207 * DKT 020228 - from now on, we don't support anything older than firm 1.00
208 * I eliminated the write register as a 2 trip of writing hi word and lo word
209 * and force this to write only 4 bytes at a time.
210 * NOTE: this should work with all the firmware from 1.00 and newer
211 */
212static int b2c2_usb_write_dw(struct usb_b2c2_usb *b2c2, u16 wRegOffsPCI, u32 val)
213{
214 u16 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI);
215 int len = usb_control_msg(b2c2->udev,
216 B2C2_USB_CTRL_PIPE_OUT,
217 B2C2_USB_WRITE_REG,
218 RTYPE_WRITE_DW_1,
219 wAddress,
220 0,
221 &val,
222 sizeof(u32),
223 B2C2_WAIT_FOR_OPERATION_RDW * 1000);
224
225 if (len != sizeof(u32)) {
226 err("error while reading dword from %d (%d).",wAddress,wRegOffsPCI);
227 return -EIO;
228 } else
229 return 0;
230}
231
232/*
233 * DKT 010817 - add support for V8 memory read/write and flash update
234 */
235static int b2c2_usb_v8_memory_req(struct usb_b2c2_usb *b2c2,
236 b2c2_usb_request_t req, u8 page, u16 wAddress,
237 u16 buflen, u8 *pbBuffer)
238{
239 u8 dwRequestType;
240 u16 wIndex;
241 int nWaitTime,pipe,len;
242
243 wIndex = page << 8;
244
245 switch (req) {
246 case B2C2_USB_READ_V8_MEM:
247 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ;
248 dwRequestType = (u8) RTYPE_READ_V8_MEMORY;
249 pipe = B2C2_USB_CTRL_PIPE_IN;
250 break;
251 case B2C2_USB_WRITE_V8_MEM:
252 wIndex |= pbBuffer[0];
253 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8WRITE;
254 dwRequestType = (u8) RTYPE_WRITE_V8_MEMORY;
255 pipe = B2C2_USB_CTRL_PIPE_OUT;
256 break;
257 case B2C2_USB_FLASH_BLOCK:
258 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8FLASH;
259 dwRequestType = (u8) RTYPE_WRITE_V8_FLASH;
260 pipe = B2C2_USB_CTRL_PIPE_OUT;
261 break;
262 default:
263 deb_info("unsupported request for v8_mem_req %x.\n",req);
264 return -EINVAL;
265 }
266 len = usb_control_msg(b2c2->udev,pipe,
267 req,
268 dwRequestType,
269 wAddress,
270 wIndex,
271 pbBuffer,
272 buflen,
273 nWaitTime * 1000);
274 return len == buflen ? 0 : -EIO;
275}
276
277static int b2c2_usb_i2c_req(struct usb_b2c2_usb *b2c2,
278 b2c2_usb_request_t req, b2c2_usb_i2c_function_t func,
279 u8 port, u8 chipaddr, u8 addr, u8 buflen, u8 *buf)
280{
281 u16 wValue, wIndex;
282 int nWaitTime,pipe,len;
283 u8 dwRequestType;
284
285 switch (func) {
286 case USB_FUNC_I2C_WRITE:
287 case USB_FUNC_I2C_MULTIWRITE:
288 case USB_FUNC_I2C_REPEATWRITE:
289 /* DKT 020208 - add this to support special case of DiSEqC */
290 case USB_FUNC_I2C_CHECKWRITE:
291 pipe = B2C2_USB_CTRL_PIPE_OUT;
292 nWaitTime = 2;
293 dwRequestType = (u8) RTYPE_GENERIC;
294 break;
295 case USB_FUNC_I2C_READ:
296 case USB_FUNC_I2C_REPEATREAD:
297 pipe = B2C2_USB_CTRL_PIPE_IN;
298 nWaitTime = 2;
299 dwRequestType = (u8) RTYPE_GENERIC;
300 break;
301 default:
302 deb_info("unsupported function for i2c_req %x\n",func);
303 return -EINVAL;
304 }
305 wValue = (func << 8 ) | port;
306 wIndex = (chipaddr << 8 ) | addr;
307
308 len = usb_control_msg(b2c2->udev,pipe,
309 req,
310 dwRequestType,
311 addr,
312 wIndex,
313 buf,
314 buflen,
315 nWaitTime * 1000);
316 return len == buflen ? 0 : -EIO;
317}
318
319int static b2c2_usb_utility_req(struct usb_b2c2_usb *b2c2, int set,
320 b2c2_usb_utility_function_t func, u8 extra, u16 wIndex,
321 u16 buflen, u8 *pvBuffer)
322{
323 u16 wValue;
324 int nWaitTime = 2,
325 pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN,
326 len;
327
328 wValue = (func << 8) | extra;
329
330 len = usb_control_msg(b2c2->udev,pipe,
331 B2C2_USB_UTILITY,
332 (u8) RTYPE_GENERIC,
333 wValue,
334 wIndex,
335 pvBuffer,
336 buflen,
337 nWaitTime * 1000);
338 return len == buflen ? 0 : -EIO;
339}
340
341
342
343static void b2c2_dumpfourreg(struct usb_b2c2_usb *b2c2, u16 offs)
344{
345 u32 r0,r1,r2,r3;
346 r0 = r1 = r2 = r3 = 0;
347 r0 = b2c2_usb_read_dw(b2c2,offs);
348 r1 = b2c2_usb_read_dw(b2c2,offs + 0x04);
349 r2 = b2c2_usb_read_dw(b2c2,offs + 0x08);
350 r3 = b2c2_usb_read_dw(b2c2,offs + 0x0c);
351 deb_ctrl("dump: offset: %03x, %08x, %08x, %08x, %08x\n",offs,r0,r1,r2,r3);
352}
353
354static void b2c2_urb_complete(struct urb *urb, struct pt_regs *ptregs)
355{
356 struct usb_b2c2_usb *b2c2 = urb->context;
357 deb_ts("urb completed, bufsize: %d\n",urb->transfer_buffer_length);
358
359// urb_submit_urb(urb,GFP_ATOMIC); enable for real action
360}
361
362static void b2c2_exit_usb(struct usb_b2c2_usb *b2c2)
363{
364 int i;
365 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++)
366 if (b2c2->iso_urb[i] != NULL) { /* not sure about unlink_urb and iso-urbs TODO */
367 deb_info("unlinking/killing urb no. %d\n",i);
368#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,7)
369 usb_unlink_urb(b2c2->iso_urb[i]);
370#else
371 usb_kill_urb(b2c2->iso_urb[i]);
372#endif
373 usb_free_urb(b2c2->iso_urb[i]);
374 }
375
376 if (b2c2->iso_buffer != NULL)
377 pci_free_consistent(NULL,b2c2->buffer_size, b2c2->iso_buffer, b2c2->iso_dma_handle);
378
379}
380
381static int b2c2_init_usb(struct usb_b2c2_usb *b2c2)
382{
383 u16 frame_size = le16_to_cpu(b2c2->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize);
384 int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * frame_size,i,j,ret;
385 int buffer_offset = 0;
386
387 deb_info("creating %d iso-urbs with %d frames each of %d bytes size = %d.\n",
388 B2C2_USB_NUM_ISO_URB, B2C2_USB_FRAMES_PER_ISO, frame_size,bufsize);
389
390 b2c2->iso_buffer = pci_alloc_consistent(NULL,bufsize,&b2c2->iso_dma_handle);
391 if (b2c2->iso_buffer == NULL)
392 return -ENOMEM;
393 memset(b2c2->iso_buffer, 0, bufsize);
394 b2c2->buffer_size = bufsize;
395
396 /* creating iso urbs */
397 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++)
398 if (!(b2c2->iso_urb[i] = usb_alloc_urb(B2C2_USB_FRAMES_PER_ISO,GFP_ATOMIC))) {
399 ret = -ENOMEM;
400 goto urb_error;
401 }
402 /* initialising and submitting iso urbs */
403 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) {
404 int frame_offset = 0;
405 struct urb *urb = b2c2->iso_urb[i];
406 deb_info("initializing and submitting urb no. %d (buf_offset: %d).\n",i,buffer_offset);
407
408 urb->dev = b2c2->udev;
409 urb->context = b2c2;
410 urb->complete = b2c2_urb_complete;
411 urb->pipe = B2C2_USB_DATA_PIPE;
412 urb->transfer_flags = URB_ISO_ASAP;
413 urb->interval = 1;
414 urb->number_of_packets = B2C2_USB_FRAMES_PER_ISO;
415 urb->transfer_buffer_length = frame_size * B2C2_USB_FRAMES_PER_ISO;
416 urb->transfer_buffer = b2c2->iso_buffer + buffer_offset;
417
418 buffer_offset += frame_size * B2C2_USB_FRAMES_PER_ISO;
419 for (j = 0; j < B2C2_USB_FRAMES_PER_ISO; j++) {
420 deb_info("urb no: %d, frame: %d, frame_offset: %d\n",i,j,frame_offset);
421 urb->iso_frame_desc[j].offset = frame_offset;
422 urb->iso_frame_desc[j].length = frame_size;
423 frame_offset += frame_size;
424 }
425
426 if ((ret = usb_submit_urb(b2c2->iso_urb[i],GFP_ATOMIC))) {
427 err("submitting urb %d failed with %d.",i,ret);
428 goto urb_error;
429 }
430 deb_info("submitted urb no. %d.\n",i);
431 }
432
433 ret = 0;
434 goto success;
435urb_error:
436 b2c2_exit_usb(b2c2);
437success:
438 return ret;
439}
440
441static int b2c2_usb_probe(struct usb_interface *intf,
442 const struct usb_device_id *id)
443{
444 struct usb_device *udev = interface_to_usbdev(intf);
445 struct usb_b2c2_usb *b2c2 = NULL;
446 int ret;
447
448 b2c2 = kmalloc(sizeof(struct usb_b2c2_usb),GFP_KERNEL);
449 if (b2c2 == NULL) {
450 err("no memory");
451 return -ENOMEM;
452 }
453 b2c2->udev = udev;
454 b2c2->uintf = intf;
455
456 /* use the alternate setting with the larges buffer */
457 usb_set_interface(udev,0,1);
458
459 if ((ret = b2c2_init_usb(b2c2)))
460 goto usb_init_error;
461
462 usb_set_intfdata(intf,b2c2);
463
464 switch (udev->speed) {
465 case USB_SPEED_LOW:
466 err("cannot handle USB speed because it is to sLOW.");
467 break;
468 case USB_SPEED_FULL:
469 info("running at FULL speed.");
470 break;
471 case USB_SPEED_HIGH:
472 info("running at HIGH speed.");
473 break;
474 case USB_SPEED_UNKNOWN: /* fall through */
475 default:
476 err("cannot handle USB speed because it is unkown.");
477 break;
478 }
479
480 b2c2_dumpfourreg(b2c2,0x200);
481 b2c2_dumpfourreg(b2c2,0x300);
482 b2c2_dumpfourreg(b2c2,0x400);
483 b2c2_dumpfourreg(b2c2,0x700);
484
485
486 if (ret == 0)
487 info("%s successfully initialized and connected.",DRIVER_DESC);
488 else
489 info("%s error while loading driver (%d)",DRIVER_DESC,ret);
490
491 ret = 0;
492 goto success;
493
494usb_init_error:
495 kfree(b2c2);
496success:
497 return ret;
498}
499
500static void b2c2_usb_disconnect(struct usb_interface *intf)
501{
502 struct usb_b2c2_usb *b2c2 = usb_get_intfdata(intf);
503 usb_set_intfdata(intf,NULL);
504 if (b2c2 != NULL) {
505 b2c2_exit_usb(b2c2);
506 kfree(b2c2);
507 }
508 info("%s successfully deinitialized and disconnected.",DRIVER_DESC);
509
510}
511
512static struct usb_device_id b2c2_usb_table [] = {
513 { USB_DEVICE(0x0af7, 0x0101) }
514};
515
516/* usb specific object needed to register this driver with the usb subsystem */
517static struct usb_driver b2c2_usb_driver = {
518 .owner = THIS_MODULE,
519 .name = "dvb_b2c2_usb",
520 .probe = b2c2_usb_probe,
521 .disconnect = b2c2_usb_disconnect,
522 .id_table = b2c2_usb_table,
523};
524
525/* module stuff */
526static int __init b2c2_usb_init(void)
527{
528 int result;
529 if ((result = usb_register(&b2c2_usb_driver))) {
530 err("usb_register failed. Error number %d",result);
531 return result;
532 }
533
534 return 0;
535}
536
537static void __exit b2c2_usb_exit(void)
538{
539 /* deregister this driver from the USB subsystem */
540 usb_deregister(&b2c2_usb_driver);
541}
542
543module_init (b2c2_usb_init);
544module_exit (b2c2_usb_exit);
545
546MODULE_AUTHOR(DRIVER_AUTHOR);
547MODULE_DESCRIPTION(DRIVER_DESC);
548MODULE_LICENSE("GPL");
549MODULE_DEVICE_TABLE(usb, b2c2_usb_table);
diff --git a/drivers/media/dvb/b2c2/flexcop-common.h b/drivers/media/dvb/b2c2/flexcop-common.h
new file mode 100644
index 000000000000..773d158032df
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-common.h
@@ -0,0 +1,164 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-common.h - common header file for device-specific source files also.
5 *
6 * see flexcop.c for copyright information.
7 */
8#ifndef __FLEXCOP_COMMON_H__
9#define __FLEXCOP_COMMON_H__
10
11#include <linux/config.h>
12#include <linux/pci.h>
13
14#include "flexcop-reg.h"
15
16#include "dmxdev.h"
17#include "dvb_demux.h"
18#include "dvb_filter.h"
19#include "dvb_net.h"
20#include "dvb_frontend.h"
21
22#define FC_MAX_FEED 256
23
24#ifndef FC_LOG_PREFIX
25#warning please define a log prefix for your file, using a default one
26#define FC_LOG_PREFIX "b2c2-undef"
27#endif
28
29/* Steal from usb.h */
30#undef err
31#define err(format, arg...) printk(KERN_ERR FC_LOG_PREFIX ": " format "\n" , ## arg)
32#undef info
33#define info(format, arg...) printk(KERN_INFO FC_LOG_PREFIX ": " format "\n" , ## arg)
34#undef warn
35#define warn(format, arg...) printk(KERN_WARNING FC_LOG_PREFIX ": " format "\n" , ## arg)
36
37struct flexcop_dma {
38 struct pci_dev *pdev;
39
40 u8 *cpu_addr0;
41 dma_addr_t dma_addr0;
42 u8 *cpu_addr1;
43 dma_addr_t dma_addr1;
44 u32 size; /* size of each address in bytes */
45};
46
47/* Control structure for data definitions that are common to
48 * the B2C2-based PCI and USB devices.
49 */
50struct flexcop_device {
51 /* general */
52 struct device *dev; /* for firmware_class */
53
54#define FC_STATE_DVB_INIT 0x01
55#define FC_STATE_I2C_INIT 0x02
56#define FC_STATE_FE_INIT 0x04
57 int init_state;
58
59 /* device information */
60 int has_32_hw_pid_filter;
61 flexcop_revision_t rev;
62 flexcop_device_type_t dev_type;
63 flexcop_bus_t bus_type;
64
65 /* dvb stuff */
66 struct dvb_adapter dvb_adapter;
67 struct dvb_frontend *fe;
68 struct dvb_net dvbnet;
69 struct dvb_demux demux;
70 struct dmxdev dmxdev;
71 struct dmx_frontend hw_frontend;
72 struct dmx_frontend mem_frontend;
73 int (*fe_sleep) (struct dvb_frontend *);
74
75 struct i2c_adapter i2c_adap;
76 struct semaphore i2c_sem;
77
78 struct module *owner;
79
80 /* options and status */
81 int extra_feedcount;
82 int feedcount;
83 int pid_filtering;
84 int fullts_streaming_state;
85
86 /* bus specific callbacks */
87 flexcop_ibi_value (*read_ibi_reg) (struct flexcop_device *, flexcop_ibi_register);
88 int (*write_ibi_reg) (struct flexcop_device *, flexcop_ibi_register, flexcop_ibi_value);
89
90
91 int (*i2c_request) (struct flexcop_device*, flexcop_access_op_t, flexcop_i2c_port_t, u8 chipaddr, u8 addr, u8 *buf, u16 len);
92 int (*stream_control) (struct flexcop_device*, int);
93
94 int (*get_mac_addr) (struct flexcop_device *fc, int extended);
95
96 void *bus_specific;
97};
98
99/* exported prototypes */
100
101/* from flexcop.c */
102void flexcop_pass_dmx_data(struct flexcop_device *fc, u8 *buf, u32 len);
103void flexcop_pass_dmx_packets(struct flexcop_device *fc, u8 *buf, u32 no);
104
105struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len);
106void flexcop_device_kfree(struct flexcop_device*);
107
108int flexcop_device_initialize(struct flexcop_device*);
109void flexcop_device_exit(struct flexcop_device *fc);
110
111/* from flexcop-dma.c */
112int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size);
113void flexcop_dma_free(struct flexcop_dma *dma);
114
115int flexcop_dma_control_timer_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff);
116int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff);
117int flexcop_dma_control_packet_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff);
118int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma, flexcop_dma_index_t dma_idx,flexcop_dma_addr_index_t index);
119int flexcop_dma_config_timer(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 cycles);
120int flexcop_dma_config_packet_count(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 packets);
121
122/* from flexcop-eeprom.c */
123/* the PCI part uses this call to get the MAC address, the USB part has its own */
124int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended);
125
126/* from flexcop-i2c.c */
127/* the PCI part uses this a i2c_request callback, whereas the usb part has its own
128 * one. We have it in flexcop-i2c.c, because it is going via the actual
129 * I2C-channel of the flexcop.
130 */
131int flexcop_i2c_request(struct flexcop_device*, flexcop_access_op_t,
132 flexcop_i2c_port_t, u8 chipaddr, u8 addr, u8 *buf, u16 len);
133
134/* from flexcop-sram.c */
135int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target);
136void flexcop_wan_set_speed(struct flexcop_device *fc, flexcop_wan_speed_t s);
137void flexcop_sram_ctrl(struct flexcop_device *fc, int usb_wan, int sramdma, int maximumfill);
138
139/* global prototypes for the flexcop-chip */
140/* from flexcop-fe-tuner.c */
141int flexcop_frontend_init(struct flexcop_device *card);
142void flexcop_frontend_exit(struct flexcop_device *fc);
143
144/* from flexcop-i2c.c */
145int flexcop_i2c_init(struct flexcop_device *fc);
146void flexcop_i2c_exit(struct flexcop_device *fc);
147
148/* from flexcop-sram.c */
149int flexcop_sram_init(struct flexcop_device *fc);
150
151/* from flexcop-misc.c */
152void flexcop_determine_revision(struct flexcop_device *fc);
153void flexcop_device_name(struct flexcop_device *fc,const char *prefix,const char *suffix);
154
155/* from flexcop-hw-filter.c */
156int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *dvbdmxfeed, int onoff);
157void flexcop_hw_filter_init(struct flexcop_device *fc);
158
159void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff);
160
161void flexcop_set_mac_filter(struct flexcop_device *fc, u8 mac[6]);
162void flexcop_mac_filter_ctrl(struct flexcop_device *fc, int onoff);
163
164#endif
diff --git a/drivers/media/dvb/b2c2/flexcop-dma.c b/drivers/media/dvb/b2c2/flexcop-dma.c
new file mode 100644
index 000000000000..8d2706075360
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-dma.c
@@ -0,0 +1,149 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-dma.c - methods for configuring and controlling the DMA of the FlexCop.
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size)
11{
12 u8 *tcpu;
13 dma_addr_t tdma;
14
15 if (size % 2) {
16 err("dma buffersize has to be even.");
17 return -EINVAL;
18 }
19
20 if ((tcpu = pci_alloc_consistent(pdev, size, &tdma)) != NULL) {
21 dma->pdev = pdev;
22 dma->cpu_addr0 = tcpu;
23 dma->dma_addr0 = tdma;
24 dma->cpu_addr1 = tcpu + size/2;
25 dma->dma_addr1 = tdma + size/2;
26 dma->size = size/2;
27 return 0;
28 }
29 return -ENOMEM;
30}
31EXPORT_SYMBOL(flexcop_dma_allocate);
32
33void flexcop_dma_free(struct flexcop_dma *dma)
34{
35 pci_free_consistent(dma->pdev, dma->size*2,dma->cpu_addr0, dma->dma_addr0);
36 memset(dma,0,sizeof(struct flexcop_dma));
37}
38EXPORT_SYMBOL(flexcop_dma_free);
39
40int flexcop_dma_control_timer_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff)
41{
42 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
43
44 if (no & FC_DMA_1)
45 v.ctrl_208.DMA1_Timer_Enable_sig = onoff;
46
47 if (no & FC_DMA_2)
48 v.ctrl_208.DMA2_Timer_Enable_sig = onoff;
49
50 fc->write_ibi_reg(fc,ctrl_208,v);
51 return 0;
52}
53EXPORT_SYMBOL(flexcop_dma_control_timer_irq);
54
55int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff)
56{
57 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
58
59 if (no & FC_DMA_1)
60 v.ctrl_208.DMA1_IRQ_Enable_sig = onoff;
61
62 if (no & FC_DMA_2)
63 v.ctrl_208.DMA2_IRQ_Enable_sig = onoff;
64
65 fc->write_ibi_reg(fc,ctrl_208,v);
66 return 0;
67}
68EXPORT_SYMBOL(flexcop_dma_control_size_irq);
69
70int flexcop_dma_control_packet_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff)
71{
72 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
73
74 if (no & FC_DMA_1)
75 v.ctrl_208.DMA1_Size_IRQ_Enable_sig = onoff;
76
77 if (no & FC_DMA_2)
78 v.ctrl_208.DMA2_Size_IRQ_Enable_sig = onoff;
79
80 fc->write_ibi_reg(fc,ctrl_208,v);
81 return 0;
82}
83EXPORT_SYMBOL(flexcop_dma_control_packet_irq);
84
85int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma, flexcop_dma_index_t dma_idx,flexcop_dma_addr_index_t index)
86{
87
88 flexcop_ibi_value v0x0,v0x4,v0xc;
89 v0x0.raw = v0x4.raw = v0xc.raw = 0;
90
91 v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2;
92 v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2;
93 v0x4.dma_0x4_write.dma_addr_size = dma->size / 4;
94
95 if (index & FC_DMA_SUBADDR_0)
96 v0x0.dma_0x0.dma_0start = 1;
97
98 if (index & FC_DMA_SUBADDR_1)
99 v0xc.dma_0xc.dma_1start = 1;
100
101 if (dma_idx & FC_DMA_1) {
102 fc->write_ibi_reg(fc,dma1_000,v0x0);
103 fc->write_ibi_reg(fc,dma1_004,v0x4);
104 fc->write_ibi_reg(fc,dma1_00c,v0xc);
105 } else { /* (dma_idx & FC_DMA_2) */
106 fc->write_ibi_reg(fc,dma2_010,v0x0);
107 fc->write_ibi_reg(fc,dma2_014,v0x4);
108 fc->write_ibi_reg(fc,dma2_01c,v0xc);
109 }
110
111 return 0;
112}
113EXPORT_SYMBOL(flexcop_dma_config);
114
115static int flexcop_dma_remap(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, int onoff)
116{
117 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
118 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
119 v.dma_0xc.remap_enable = onoff;
120 fc->write_ibi_reg(fc,r,v);
121 return 0;
122}
123
124/* 1 cycles = 1.97 msec */
125int flexcop_dma_config_timer(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 cycles)
126{
127 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
128 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
129
130 flexcop_dma_remap(fc,dma_idx,0);
131
132 v.dma_0x4_write.dmatimer = cycles >> 1;
133 fc->write_ibi_reg(fc,r,v);
134 return 0;
135}
136EXPORT_SYMBOL(flexcop_dma_config_timer);
137
138int flexcop_dma_config_packet_count(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 packets)
139{
140 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
141 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
142
143 flexcop_dma_remap(fc,dma_idx,1);
144
145 v.dma_0x4_remap.DMA_maxpackets = packets;
146 fc->write_ibi_reg(fc,r,v);
147 return 0;
148}
149EXPORT_SYMBOL(flexcop_dma_config_packet_count);
diff --git a/drivers/media/dvb/b2c2/flexcop-eeprom.c b/drivers/media/dvb/b2c2/flexcop-eeprom.c
new file mode 100644
index 000000000000..bbcf070a178d
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-eeprom.c
@@ -0,0 +1,153 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-eeprom.c - eeprom access methods (currently only MAC address reading is used)
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10#if 0
11/*EEPROM (Skystar2 has one "24LC08B" chip on board) */
12static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len)
13{
14 return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len);
15}
16
17static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 *wbuf, u8 *rbuf, int retries)
18{
19 int i;
20
21 for (i = 0; i < retries; i++) {
22 if (eeprom_write(adapter, addr, wbuf, len) == len) {
23 if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1)
24 return 1;
25 }
26 }
27
28 return 0;
29}
30
31/* These functions could be used to unlock SkyStar2 cards. */
32
33static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len)
34{
35 u8 rbuf[20];
36 u8 wbuf[20];
37
38 if (len != 16)
39 return 0;
40
41 memcpy(wbuf, key, len);
42
43 wbuf[16] = 0;
44 wbuf[17] = 0;
45 wbuf[18] = 0;
46 wbuf[19] = calc_lrc(wbuf, 19);
47
48 return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);
49}
50
51static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len)
52{
53 u8 buf[20];
54
55 if (len != 16)
56 return 0;
57
58 if (eeprom_lrc_read(adapter, 0x3e4, 20, buf, 4) == 0)
59 return 0;
60
61 memcpy(key, buf, len);
62
63 return 1;
64}
65
66static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)
67{
68 u8 tmp[8];
69
70 if (type != 0) {
71 tmp[0] = mac[0];
72 tmp[1] = mac[1];
73 tmp[2] = mac[2];
74 tmp[3] = mac[5];
75 tmp[4] = mac[6];
76 tmp[5] = mac[7];
77
78 } else {
79
80 tmp[0] = mac[0];
81 tmp[1] = mac[1];
82 tmp[2] = mac[2];
83 tmp[3] = mac[3];
84 tmp[4] = mac[4];
85 tmp[5] = mac[5];
86 }
87
88 tmp[6] = 0;
89 tmp[7] = calc_lrc(tmp, 7);
90
91 if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)
92 return 1;
93
94 return 0;
95}
96
97static int flexcop_eeprom_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len)
98{
99 return fc->i2c_request(fc,FC_READ,FC_I2C_PORT_EEPROM,0x50,addr,buf,len);
100}
101
102#endif
103
104static u8 calc_lrc(u8 *buf, int len)
105{
106 int i;
107 u8 sum = 0;
108 for (i = 0; i < len; i++)
109 sum = sum ^ buf[i];
110 return sum;
111}
112
113static int flexcop_eeprom_request(struct flexcop_device *fc, flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries)
114{
115 int i,ret = 0;
116 u8 chipaddr = 0x50 | ((addr >> 8) & 3);
117 for (i = 0; i < retries; i++)
118 if ((ret = fc->i2c_request(fc,op,FC_I2C_PORT_EEPROM,chipaddr,addr & 0xff,buf,len)) == 0)
119 break;
120 return ret;
121}
122
123static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len, int retries)
124{
125 int ret = flexcop_eeprom_request(fc,FC_READ,addr,buf,len,retries);
126 if (ret == 0)
127 if (calc_lrc(buf, len - 1) != buf[len - 1])
128 ret = -EINVAL;
129 return ret;
130}
131
132/* JJ's comment about extended == 1: it is not presently used anywhere but was
133 * added to the low-level functions for possible support of EUI64
134 */
135int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)
136{
137 u8 buf[8];
138 int ret = 0;
139
140 if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) {
141 if (extended != 0) {
142 err("TODO: extended (EUI64) MAC addresses aren't completely supported yet");
143 ret = -EINVAL;
144/* memcpy(fc->dvb_adapter.proposed_mac,buf,3);
145 mac[3] = 0xfe;
146 mac[4] = 0xff;
147 memcpy(&fc->dvb_adapter.proposed_mac[3],&buf[5],3); */
148 } else
149 memcpy(fc->dvb_adapter.proposed_mac,buf,6);
150 }
151 return ret;
152}
153EXPORT_SYMBOL(flexcop_eeprom_check_mac_addr);
diff --git a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
new file mode 100644
index 000000000000..0410cc96a48e
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
@@ -0,0 +1,413 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-fe-tuner.c - methods for attaching a frontend and controlling DiSEqC.
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10#include "stv0299.h"
11#include "mt352.h"
12#include "nxt2002.h"
13#include "bcm3510.h"
14#include "stv0297.h"
15#include "mt312.h"
16
17/* lnb control */
18
19static int flexcop_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
20{
21 struct flexcop_device *fc = fe->dvb->priv;
22 flexcop_ibi_value v;
23 deb_tuner("polarity/voltage = %u\n", voltage);
24
25 v = fc->read_ibi_reg(fc, misc_204);
26 switch (voltage) {
27 case SEC_VOLTAGE_OFF:
28 v.misc_204.ACPI1_sig = 1;
29 break;
30 case SEC_VOLTAGE_13:
31 v.misc_204.ACPI1_sig = 0;
32 v.misc_204.LNB_L_H_sig = 0;
33 break;
34 case SEC_VOLTAGE_18:
35 v.misc_204.ACPI1_sig = 0;
36 v.misc_204.LNB_L_H_sig = 1;
37 break;
38 default:
39 err("unknown SEC_VOLTAGE value");
40 return -EINVAL;
41 }
42 return fc->write_ibi_reg(fc, misc_204, v);
43}
44
45static int flexcop_sleep(struct dvb_frontend* fe)
46{
47 struct flexcop_device *fc = fe->dvb->priv;
48/* flexcop_ibi_value v = fc->read_ibi_reg(fc,misc_204); */
49
50 if (fc->fe_sleep)
51 return fc->fe_sleep(fe);
52
53/* v.misc_204.ACPI3_sig = 1;
54 fc->write_ibi_reg(fc,misc_204,v);*/
55
56 return 0;
57}
58
59static int flexcop_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
60{
61 /* u16 wz_half_period_for_45_mhz[] = { 0x01ff, 0x0154, 0x00ff, 0x00cc }; */
62 struct flexcop_device *fc = fe->dvb->priv;
63 flexcop_ibi_value v;
64 u16 ax;
65 v.raw = 0;
66
67 deb_tuner("tone = %u\n",tone);
68
69 switch (tone) {
70 case SEC_TONE_ON:
71 ax = 0x01ff;
72 break;
73 case SEC_TONE_OFF:
74 ax = 0;
75 break;
76 default:
77 err("unknown SEC_TONE value");
78 return -EINVAL;
79 }
80
81 v.lnb_switch_freq_200.LNB_CTLPrescaler_sig = 1; /* divide by 2 */
82
83 v.lnb_switch_freq_200.LNB_CTLHighCount_sig = ax;
84 v.lnb_switch_freq_200.LNB_CTLLowCount_sig = ax == 0 ? 0x1ff : ax;
85
86 return fc->write_ibi_reg(fc,lnb_switch_freq_200,v);
87}
88
89static void flexcop_diseqc_send_bit(struct dvb_frontend* fe, int data)
90{
91 flexcop_set_tone(fe, SEC_TONE_ON);
92 udelay(data ? 500 : 1000);
93 flexcop_set_tone(fe, SEC_TONE_OFF);
94 udelay(data ? 1000 : 500);
95}
96
97static void flexcop_diseqc_send_byte(struct dvb_frontend* fe, int data)
98{
99 int i, par = 1, d;
100
101 for (i = 7; i >= 0; i--) {
102 d = (data >> i) & 1;
103 par ^= d;
104 flexcop_diseqc_send_bit(fe, d);
105 }
106
107 flexcop_diseqc_send_bit(fe, par);
108}
109
110static int flexcop_send_diseqc_msg(struct dvb_frontend* fe, int len, u8 *msg, unsigned long burst)
111{
112 int i;
113
114 flexcop_set_tone(fe, SEC_TONE_OFF);
115 mdelay(16);
116
117 for (i = 0; i < len; i++)
118 flexcop_diseqc_send_byte(fe,msg[i]);
119
120 mdelay(16);
121
122 if (burst != -1) {
123 if (burst)
124 flexcop_diseqc_send_byte(fe, 0xff);
125 else {
126 flexcop_set_tone(fe, SEC_TONE_ON);
127 udelay(12500);
128 flexcop_set_tone(fe, SEC_TONE_OFF);
129 }
130 msleep(20);
131 }
132 return 0;
133}
134
135static int flexcop_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
136{
137 return flexcop_send_diseqc_msg(fe, cmd->msg_len, cmd->msg, 0);
138}
139
140static int flexcop_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
141{
142 return flexcop_send_diseqc_msg(fe, 0, NULL, minicmd);
143}
144
145/* dvb-s stv0299 */
146static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
147{
148 u8 aclk = 0;
149 u8 bclk = 0;
150
151 if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
152 else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
153 else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
154 else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
155 else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
156 else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
157
158 stv0299_writereg (fe, 0x13, aclk);
159 stv0299_writereg (fe, 0x14, bclk);
160 stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
161 stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
162 stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
163
164 return 0;
165}
166
167static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
168{
169 u8 buf[4];
170 u32 div;
171 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
172 struct flexcop_device *fc = fe->dvb->priv;
173
174 div = params->frequency / 125;
175
176 buf[0] = (div >> 8) & 0x7f;
177 buf[1] = div & 0xff;
178 buf[2] = 0x84; /* 0xC4 */
179 buf[3] = 0x08;
180
181 if (params->frequency < 1500000) buf[3] |= 0x10;
182
183 if (i2c_transfer(&fc->i2c_adap, &msg, 1) != 1)
184 return -EIO;
185 return 0;
186}
187
188static u8 samsung_tbmu24112_inittab[] = {
189 0x01, 0x15,
190 0x02, 0x30,
191 0x03, 0x00,
192 0x04, 0x7D,
193 0x05, 0x35,
194 0x06, 0x02,
195 0x07, 0x00,
196 0x08, 0xC3,
197 0x0C, 0x00,
198 0x0D, 0x81,
199 0x0E, 0x23,
200 0x0F, 0x12,
201 0x10, 0x7E,
202 0x11, 0x84,
203 0x12, 0xB9,
204 0x13, 0x88,
205 0x14, 0x89,
206 0x15, 0xC9,
207 0x16, 0x00,
208 0x17, 0x5C,
209 0x18, 0x00,
210 0x19, 0x00,
211 0x1A, 0x00,
212 0x1C, 0x00,
213 0x1D, 0x00,
214 0x1E, 0x00,
215 0x1F, 0x3A,
216 0x20, 0x2E,
217 0x21, 0x80,
218 0x22, 0xFF,
219 0x23, 0xC1,
220 0x28, 0x00,
221 0x29, 0x1E,
222 0x2A, 0x14,
223 0x2B, 0x0F,
224 0x2C, 0x09,
225 0x2D, 0x05,
226 0x31, 0x1F,
227 0x32, 0x19,
228 0x33, 0xFE,
229 0x34, 0x93,
230 0xff, 0xff,
231};
232
233static struct stv0299_config samsung_tbmu24112_config = {
234 .demod_address = 0x68,
235 .inittab = samsung_tbmu24112_inittab,
236 .mclk = 88000000UL,
237 .invert = 0,
238 .enhanced_tuning = 0,
239 .skip_reinit = 0,
240 .lock_output = STV0229_LOCKOUTPUT_LK,
241 .volt13_op0_op1 = STV0299_VOLT13_OP1,
242 .min_delay_ms = 100,
243 .set_symbol_rate = samsung_tbmu24112_set_symbol_rate,
244 .pll_set = samsung_tbmu24112_pll_set,
245};
246
247/* dvb-t mt352 */
248static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
249{
250 static u8 mt352_clock_config [] = { 0x89, 0x18, 0x2d };
251 static u8 mt352_reset [] = { 0x50, 0x80 };
252 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
253 static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0xa1 };
254 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
255
256 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
257 udelay(2000);
258 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
259 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
260
261 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
262 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
263
264 return 0;
265}
266
267static int samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
268{
269 u32 div;
270 unsigned char bs = 0;
271
272 #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
273 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
274
275 if (params->frequency >= 48000000 && params->frequency <= 154000000) bs = 0x09;
276 if (params->frequency >= 161000000 && params->frequency <= 439000000) bs = 0x0a;
277 if (params->frequency >= 447000000 && params->frequency <= 863000000) bs = 0x08;
278
279 pllbuf[0] = 0xc2; /* Note: non-linux standard PLL i2c address */
280 pllbuf[1] = div >> 8;
281 pllbuf[2] = div & 0xff;
282 pllbuf[3] = 0xcc;
283 pllbuf[4] = bs;
284
285 return 0;
286}
287
288static struct mt352_config samsung_tdtc9251dh0_config = {
289 .demod_address = 0x0f,
290 .demod_init = samsung_tdtc9251dh0_demod_init,
291 .pll_set = samsung_tdtc9251dh0_pll_set,
292};
293
294static int flexcop_fe_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
295{
296 struct flexcop_device *fc = fe->dvb->priv;
297 return request_firmware(fw, name, fc->dev);
298}
299
300static struct nxt2002_config samsung_tbmv_config = {
301 .demod_address = 0x0a,
302 .request_firmware = flexcop_fe_request_firmware,
303};
304
305static struct bcm3510_config air2pc_atsc_first_gen_config = {
306 .demod_address = 0x0f,
307 .request_firmware = flexcop_fe_request_firmware,
308};
309
310static int skystar23_samsung_tbdu18132_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
311{
312 u8 buf[4];
313 u32 div;
314 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
315 struct flexcop_device *fc = fe->dvb->priv;
316
317 div = (params->frequency + (125/2)) / 125;
318
319 buf[0] = (div >> 8) & 0x7f;
320 buf[1] = (div >> 0) & 0xff;
321 buf[2] = 0x84 | ((div >> 10) & 0x60);
322 buf[3] = 0x80;
323
324 if (params->frequency < 1550000)
325 buf[3] |= 0x02;
326
327 if (i2c_transfer(&fc->i2c_adap, &msg, 1) != 1)
328 return -EIO;
329 return 0;
330}
331
332static struct mt312_config skystar23_samsung_tbdu18132_config = {
333
334 .demod_address = 0x0e,
335 .pll_set = skystar23_samsung_tbdu18132_pll_set,
336};
337
338static struct stv0297_config alps_tdee4_stv0297_config = {
339 .demod_address = 0x1c,
340// .invert = 1,
341// .pll_set = alps_tdee4_stv0297_pll_set,
342};
343
344/* try to figure out the frontend, each card/box can have on of the following list */
345int flexcop_frontend_init(struct flexcop_device *fc)
346{
347 /* try the sky v2.6 (stv0299/Samsung tbmu24112(sl1935)) */
348 if ((fc->fe = stv0299_attach(&samsung_tbmu24112_config, &fc->i2c_adap)) != NULL) {
349 fc->fe->ops->set_voltage = flexcop_set_voltage;
350
351 fc->fe_sleep = fc->fe->ops->sleep;
352 fc->fe->ops->sleep = flexcop_sleep;
353
354 fc->dev_type = FC_SKY;
355 info("found the stv0299 at i2c address: 0x%02x",samsung_tbmu24112_config.demod_address);
356 } else
357 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */
358 if ((fc->fe = mt352_attach(&samsung_tdtc9251dh0_config, &fc->i2c_adap)) != NULL ) {
359 fc->dev_type = FC_AIR_DVB;
360 info("found the mt352 at i2c address: 0x%02x",samsung_tdtc9251dh0_config.demod_address);
361 } else
362 /* try the air atsc 2nd generation (nxt2002) */
363 if ((fc->fe = nxt2002_attach(&samsung_tbmv_config, &fc->i2c_adap)) != NULL) {
364 fc->dev_type = FC_AIR_ATSC2;
365 info("found the nxt2002 at i2c address: 0x%02x",samsung_tbmv_config.demod_address);
366 } else
367 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */
368 if ((fc->fe = bcm3510_attach(&air2pc_atsc_first_gen_config, &fc->i2c_adap)) != NULL) {
369 fc->dev_type = FC_AIR_ATSC1;
370 info("found the bcm3510 at i2c address: 0x%02x",air2pc_atsc_first_gen_config.demod_address);
371 } else
372 /* try the cable dvb (stv0297) */
373 if ((fc->fe = stv0297_attach(&alps_tdee4_stv0297_config, &fc->i2c_adap, 0xf8)) != NULL) {
374 fc->dev_type = FC_CABLE;
375 info("found the stv0297 at i2c address: 0x%02x",alps_tdee4_stv0297_config.demod_address);
376 } else
377 /* try the sky v2.3 (vp310/Samsung tbdu18132(tsa5059)) */
378 if ((fc->fe = vp310_attach(&skystar23_samsung_tbdu18132_config, &fc->i2c_adap)) != NULL) {
379 fc->fe->ops->diseqc_send_master_cmd = flexcop_diseqc_send_master_cmd;
380 fc->fe->ops->diseqc_send_burst = flexcop_diseqc_send_burst;
381 fc->fe->ops->set_tone = flexcop_set_tone;
382 fc->fe->ops->set_voltage = flexcop_set_voltage;
383
384 fc->fe_sleep = fc->fe->ops->sleep;
385 fc->fe->ops->sleep = flexcop_sleep;
386
387 fc->dev_type = FC_SKY_OLD;
388 info("found the vp310 (aka mt312) at i2c address: 0x%02x",skystar23_samsung_tbdu18132_config.demod_address);
389 }
390
391 if (fc->fe == NULL) {
392 err("no frontend driver found for this B2C2/FlexCop adapter");
393 return -ENODEV;
394 } else {
395 if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) {
396 err("frontend registration failed!");
397 if (fc->fe->ops->release != NULL)
398 fc->fe->ops->release(fc->fe);
399 fc->fe = NULL;
400 return -EINVAL;
401 }
402 }
403 fc->init_state |= FC_STATE_FE_INIT;
404 return 0;
405}
406
407void flexcop_frontend_exit(struct flexcop_device *fc)
408{
409 if (fc->init_state & FC_STATE_FE_INIT)
410 dvb_unregister_frontend(fc->fe);
411
412 fc->init_state &= ~FC_STATE_FE_INIT;
413}
diff --git a/drivers/media/dvb/b2c2/flexcop-hw-filter.c b/drivers/media/dvb/b2c2/flexcop-hw-filter.c
new file mode 100644
index 000000000000..2baf43d3ce8f
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-hw-filter.c
@@ -0,0 +1,204 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-hw-filter.c - pid and mac address filtering and corresponding control functions.
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10static void flexcop_rcv_data_ctrl(struct flexcop_device *fc, int onoff)
11{
12 flexcop_set_ibi_value(ctrl_208,Rcv_Data_sig,onoff);
13}
14
15void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff)
16{
17 flexcop_set_ibi_value(ctrl_208,SMC_Enable_sig,onoff);
18}
19
20void flexcop_null_filter_ctrl(struct flexcop_device *fc, int onoff)
21{
22 flexcop_set_ibi_value(ctrl_208,Null_filter_sig,onoff);
23}
24
25void flexcop_set_mac_filter(struct flexcop_device *fc, u8 mac[6])
26{
27 flexcop_ibi_value v418,v41c;
28 v41c = fc->read_ibi_reg(fc,mac_address_41c);
29
30 v418.mac_address_418.MAC1 = mac[0];
31 v418.mac_address_418.MAC2 = mac[1];
32 v418.mac_address_418.MAC3 = mac[2];
33 v418.mac_address_418.MAC6 = mac[3];
34 v41c.mac_address_41c.MAC7 = mac[4];
35 v41c.mac_address_41c.MAC8 = mac[5];
36
37 fc->write_ibi_reg(fc,mac_address_418,v418);
38 fc->write_ibi_reg(fc,mac_address_41c,v41c);
39}
40
41void flexcop_mac_filter_ctrl(struct flexcop_device *fc, int onoff)
42{
43 flexcop_set_ibi_value(ctrl_208,MAC_filter_Mode_sig,onoff);
44}
45
46static void flexcop_pid_group_filter(struct flexcop_device *fc, u16 pid, u16 mask)
47{
48 /* index_reg_310.extra_index_reg need to 0 or 7 to work */
49 flexcop_ibi_value v30c;
50 v30c.pid_filter_30c_ext_ind_0_7.Group_PID = pid;
51 v30c.pid_filter_30c_ext_ind_0_7.Group_mask = mask;
52 fc->write_ibi_reg(fc,pid_filter_30c,v30c);
53}
54
55static void flexcop_pid_group_filter_ctrl(struct flexcop_device *fc, int onoff)
56{
57 flexcop_set_ibi_value(ctrl_208,Mask_filter_sig,onoff);
58}
59
60/* this fancy define reduces the code size of the quite similar PID controlling of
61 * the first 6 PIDs
62 */
63
64#define pid_ctrl(vregname,field,enablefield,trans_field,transval) \
65 flexcop_ibi_value vpid = fc->read_ibi_reg(fc, vregname), \
66 v208 = fc->read_ibi_reg(fc, ctrl_208); \
67\
68 vpid.vregname.field = onoff ? pid : 0x1fff; \
69 vpid.vregname.trans_field = transval; \
70 v208.ctrl_208.enablefield = onoff; \
71\
72 fc->write_ibi_reg(fc,vregname,vpid); \
73 fc->write_ibi_reg(fc,ctrl_208,v208);
74
75static void flexcop_pid_Stream1_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff)
76{
77 pid_ctrl(pid_filter_300,Stream1_PID,Stream1_filter_sig,Stream1_trans,0);
78}
79
80static void flexcop_pid_Stream2_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff)
81{
82 pid_ctrl(pid_filter_300,Stream2_PID,Stream2_filter_sig,Stream2_trans,0);
83}
84
85static void flexcop_pid_PCR_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff)
86{
87 pid_ctrl(pid_filter_304,PCR_PID,PCR_filter_sig,PCR_trans,0);
88}
89
90static void flexcop_pid_PMT_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff)
91{
92 pid_ctrl(pid_filter_304,PMT_PID,PMT_filter_sig,PMT_trans,0);
93}
94
95static void flexcop_pid_EMM_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff)
96{
97 pid_ctrl(pid_filter_308,EMM_PID,EMM_filter_sig,EMM_trans,0);
98}
99
100static void flexcop_pid_ECM_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff)
101{
102 pid_ctrl(pid_filter_308,ECM_PID,ECM_filter_sig,ECM_trans,0);
103}
104
105static void flexcop_pid_control(struct flexcop_device *fc, int index, u16 pid,int onoff)
106{
107 if (pid == 0x2000)
108 return;
109
110 deb_ts("setting pid: %5d %04x at index %d '%s'\n",pid,pid,index,onoff ? "on" : "off");
111
112 /* We could use bit magic here to reduce source code size.
113 * I decided against it, but to use the real register names */
114 switch (index) {
115 case 0: flexcop_pid_Stream1_PID_ctrl(fc,pid,onoff); break;
116 case 1: flexcop_pid_Stream2_PID_ctrl(fc,pid,onoff); break;
117 case 2: flexcop_pid_PCR_PID_ctrl(fc,pid,onoff); break;
118 case 3: flexcop_pid_PMT_PID_ctrl(fc,pid,onoff); break;
119 case 4: flexcop_pid_EMM_PID_ctrl(fc,pid,onoff); break;
120 case 5: flexcop_pid_ECM_PID_ctrl(fc,pid,onoff); break;
121 default:
122 if (fc->has_32_hw_pid_filter && index < 38) {
123 flexcop_ibi_value vpid,vid;
124
125 /* set the index */
126 vid = fc->read_ibi_reg(fc,index_reg_310);
127 vid.index_reg_310.index_reg = index - 6;
128 fc->write_ibi_reg(fc,index_reg_310, vid);
129
130 vpid = fc->read_ibi_reg(fc,pid_n_reg_314);
131 vpid.pid_n_reg_314.PID = onoff ? pid : 0x1fff;
132 vpid.pid_n_reg_314.PID_enable_bit = onoff;
133 fc->write_ibi_reg(fc,pid_n_reg_314, vpid);
134 }
135 break;
136 }
137}
138
139static int flexcop_toggle_fullts_streaming(struct flexcop_device *fc,int onoff)
140{
141 if (fc->fullts_streaming_state != onoff) {
142 deb_ts("%s full TS transfer\n",onoff ? "enabling" : "disabling");
143 flexcop_pid_group_filter(fc, 0, 0x1fe0 * (!onoff));
144 flexcop_pid_group_filter_ctrl(fc,onoff);
145 fc->fullts_streaming_state = onoff;
146 }
147 return 0;
148}
149
150int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *dvbdmxfeed, int onoff)
151{
152 int max_pid_filter = 6 + fc->has_32_hw_pid_filter*32;
153
154 fc->feedcount += onoff ? 1 : -1;
155 if (dvbdmxfeed->index >= max_pid_filter)
156 fc->extra_feedcount += onoff ? 1 : -1;
157
158 /* toggle complete-TS-streaming when:
159 * - pid_filtering is not enabled and it is the first or last feed requested
160 * - pid_filtering is enabled,
161 * - but the number of requested feeds is exceeded
162 * - or the requested pid is 0x2000 */
163
164 if (!fc->pid_filtering && fc->feedcount == onoff)
165 flexcop_toggle_fullts_streaming(fc,onoff);
166
167 if (fc->pid_filtering) {
168 flexcop_pid_control(fc,dvbdmxfeed->index,dvbdmxfeed->pid,onoff);
169
170 if (fc->extra_feedcount > 0)
171 flexcop_toggle_fullts_streaming(fc,1);
172 else if (dvbdmxfeed->pid == 0x2000)
173 flexcop_toggle_fullts_streaming(fc,onoff);
174 else
175 flexcop_toggle_fullts_streaming(fc,0);
176 }
177
178 /* if it was the first or last feed request change the stream-status */
179 if (fc->feedcount == onoff) {
180 flexcop_rcv_data_ctrl(fc,onoff);
181 if (fc->stream_control)
182 fc->stream_control(fc,onoff);
183 }
184
185 return 0;
186}
187
188void flexcop_hw_filter_init(struct flexcop_device *fc)
189{
190 int i;
191 flexcop_ibi_value v;
192 for (i = 0; i < 6 + 32*fc->has_32_hw_pid_filter; i++)
193 flexcop_pid_control(fc,i,0x1fff,0);
194
195 flexcop_pid_group_filter(fc, 0, 0x1fe0);
196 flexcop_pid_group_filter_ctrl(fc,0);
197
198 v = fc->read_ibi_reg(fc,pid_filter_308);
199 v.pid_filter_308.EMM_filter_4 = 1;
200 v.pid_filter_308.EMM_filter_6 = 0;
201 fc->write_ibi_reg(fc,pid_filter_308,v);
202
203 flexcop_null_filter_ctrl(fc, 1);
204}
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
new file mode 100644
index 000000000000..be4266d4ae91
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -0,0 +1,210 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-i2c.c - flexcop internal 2Wire bus (I2C) and dvb i2c initialization
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10#define FC_MAX_I2C_RETRIES 100000
11
12static int flexcop_i2c_operation(struct flexcop_device *fc, flexcop_ibi_value *r100)
13{
14 int i;
15 flexcop_ibi_value r;
16
17 r100->tw_sm_c_100.working_start = 1;
18 deb_i2c("r100 before: %08x\n",r100->raw);
19
20 fc->write_ibi_reg(fc, tw_sm_c_100, ibi_zero);
21 fc->write_ibi_reg(fc, tw_sm_c_100, *r100); /* initiating i2c operation */
22
23 for (i = 0; i < FC_MAX_I2C_RETRIES; i++) {
24 r = fc->read_ibi_reg(fc, tw_sm_c_100);
25
26 if (!r.tw_sm_c_100.no_base_addr_ack_error) {
27 if (r.tw_sm_c_100.st_done) { /* && !r.tw_sm_c_100.working_start */
28 *r100 = r;
29 deb_i2c("i2c success\n");
30 return 0;
31 }
32 } else {
33 deb_i2c("suffering from an i2c ack_error\n");
34 return -EREMOTEIO;
35 }
36 }
37 deb_i2c("tried %d times i2c operation, never finished or too many ack errors.\n",i);
38 return -EREMOTEIO;
39}
40
41static int flexcop_i2c_read4(struct flexcop_device *fc, flexcop_ibi_value r100, u8 *buf)
42{
43 flexcop_ibi_value r104;
44 int len = r100.tw_sm_c_100.total_bytes, /* remember total_bytes is buflen-1 */
45 ret;
46
47 if ((ret = flexcop_i2c_operation(fc,&r100)) != 0) {
48 /* The Cablestar needs a different kind of i2c-transfer (does not
49 * support "Repeat Start"):
50 * wait for the ACK failure,
51 * and do a subsequent read with the Bit 30 enabled
52 */
53 r100.tw_sm_c_100.no_base_addr_ack_error = 1;
54 if ((ret = flexcop_i2c_operation(fc,&r100)) != 0) {
55 deb_i2c("no_base_addr read failed. %d\n",ret);
56 return ret;
57 }
58 }
59
60 buf[0] = r100.tw_sm_c_100.data1_reg;
61
62 if (len > 0) {
63 r104 = fc->read_ibi_reg(fc,tw_sm_c_104);
64 deb_i2c("read: r100: %08x, r104: %08x\n",r100.raw,r104.raw);
65
66 /* there is at least one more byte, otherwise we wouldn't be here */
67 buf[1] = r104.tw_sm_c_104.data2_reg;
68 if (len > 1) buf[2] = r104.tw_sm_c_104.data3_reg;
69 if (len > 2) buf[3] = r104.tw_sm_c_104.data4_reg;
70 }
71
72 return 0;
73}
74
75static int flexcop_i2c_write4(struct flexcop_device *fc, flexcop_ibi_value r100, u8 *buf)
76{
77 flexcop_ibi_value r104;
78 int len = r100.tw_sm_c_100.total_bytes; /* remember total_bytes is buflen-1 */
79 r104.raw = 0;
80
81 /* there is at least one byte, otherwise we wouldn't be here */
82 r100.tw_sm_c_100.data1_reg = buf[0];
83
84 r104.tw_sm_c_104.data2_reg = len > 0 ? buf[1] : 0;
85 r104.tw_sm_c_104.data3_reg = len > 1 ? buf[2] : 0;
86 r104.tw_sm_c_104.data4_reg = len > 2 ? buf[3] : 0;
87
88 deb_i2c("write: r100: %08x, r104: %08x\n",r100.raw,r104.raw);
89
90 /* write the additional i2c data before doing the actual i2c operation */
91 fc->write_ibi_reg(fc,tw_sm_c_104,r104);
92 return flexcop_i2c_operation(fc,&r100);
93}
94
95int flexcop_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op,
96 flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u16 len)
97{
98 int ret;
99 u16 bytes_to_transfer;
100 flexcop_ibi_value r100;
101
102 deb_i2c("op = %d\n",op);
103 r100.raw = 0;
104 r100.tw_sm_c_100.chipaddr = chipaddr;
105 r100.tw_sm_c_100.twoWS_rw = op;
106 r100.tw_sm_c_100.twoWS_port_reg = port;
107
108 while (len != 0) {
109 bytes_to_transfer = len > 4 ? 4 : len;
110
111 r100.tw_sm_c_100.total_bytes = bytes_to_transfer - 1;
112 r100.tw_sm_c_100.baseaddr = addr;
113
114 if (op == FC_READ)
115 ret = flexcop_i2c_read4(fc, r100, buf);
116 else
117 ret = flexcop_i2c_write4(fc,r100, buf);
118
119 if (ret < 0)
120 return ret;
121
122 buf += bytes_to_transfer;
123 addr += bytes_to_transfer;
124 len -= bytes_to_transfer;
125 };
126
127 return 0;
128}
129/* exported for PCI i2c */
130EXPORT_SYMBOL(flexcop_i2c_request);
131
132/* master xfer callback for demodulator */
133static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
134{
135 struct flexcop_device *fc = i2c_get_adapdata(i2c_adap);
136 int i, ret = 0;
137
138 if (down_interruptible(&fc->i2c_sem))
139 return -ERESTARTSYS;
140
141 /* reading */
142 if (num == 2 &&
143 msgs[0].flags == 0 &&
144 msgs[1].flags == I2C_M_RD &&
145 msgs[0].buf != NULL &&
146 msgs[1].buf != NULL) {
147
148 ret = fc->i2c_request(fc, FC_READ, FC_I2C_PORT_DEMOD, msgs[0].addr, msgs[0].buf[0], msgs[1].buf, msgs[1].len);
149
150 } else for (i = 0; i < num; i++) { /* writing command */
151 if (msgs[i].flags != 0 || msgs[i].buf == NULL || msgs[i].len < 2) {
152 ret = -EINVAL;
153 break;
154 }
155
156 ret = fc->i2c_request(fc, FC_WRITE, FC_I2C_PORT_DEMOD, msgs[i].addr, msgs[i].buf[0], &msgs[i].buf[1], msgs[i].len - 1);
157 }
158
159 if (ret < 0)
160 err("i2c master_xfer failed");
161 else
162 ret = num;
163
164 up(&fc->i2c_sem);
165
166 return ret;
167}
168
169static u32 flexcop_i2c_func(struct i2c_adapter *adapter)
170{
171 return I2C_FUNC_I2C;
172}
173
174static struct i2c_algorithm flexcop_algo = {
175 .name = "FlexCop I2C algorithm",
176 .id = I2C_ALGO_BIT,
177 .master_xfer = flexcop_master_xfer,
178 .functionality = flexcop_i2c_func,
179};
180
181int flexcop_i2c_init(struct flexcop_device *fc)
182{
183 int ret;
184
185 sema_init(&fc->i2c_sem,1);
186
187 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter));
188 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",I2C_NAME_SIZE);
189
190 i2c_set_adapdata(&fc->i2c_adap,fc);
191
192 fc->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
193 fc->i2c_adap.algo = &flexcop_algo;
194 fc->i2c_adap.algo_data = NULL;
195 fc->i2c_adap.id = I2C_ALGO_BIT;
196
197 if ((ret = i2c_add_adapter(&fc->i2c_adap)) < 0)
198 return ret;
199
200 fc->init_state |= FC_STATE_I2C_INIT;
201 return 0;
202}
203
204void flexcop_i2c_exit(struct flexcop_device *fc)
205{
206 if (fc->init_state & FC_STATE_I2C_INIT)
207 i2c_del_adapter(&fc->i2c_adap);
208
209 fc->init_state &= ~FC_STATE_I2C_INIT;
210}
diff --git a/drivers/media/dvb/b2c2/flexcop-misc.c b/drivers/media/dvb/b2c2/flexcop-misc.c
new file mode 100644
index 000000000000..23082545651f
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-misc.c
@@ -0,0 +1,67 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-misc.c - miscellaneous functions.
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10void flexcop_determine_revision(struct flexcop_device *fc)
11{
12 flexcop_ibi_value v = fc->read_ibi_reg(fc,misc_204);
13
14 switch (v.misc_204.Rev_N_sig_revision_hi) {
15 case 0x2:
16 deb_info("found a FlexCopII.\n");
17 fc->rev = FLEXCOP_II;
18 break;
19 case 0x3:
20 deb_info("found a FlexCopIIb.\n");
21 fc->rev = FLEXCOP_IIB;
22 break;
23 case 0x0:
24 deb_info("found a FlexCopIII.\n");
25 fc->rev = FLEXCOP_III;
26 break;
27 default:
28 err("unkown FlexCop Revision: %x. Please report the linux-dvb@linuxtv.org.",v.misc_204.Rev_N_sig_revision_hi);
29 break;
30 }
31
32 if ((fc->has_32_hw_pid_filter = v.misc_204.Rev_N_sig_caps))
33 deb_info("this FlexCop has the additional 32 hardware pid filter.\n");
34 else
35 deb_info("this FlexCop has only the 6 basic main hardware pid filter.\n");
36 /* bus parts have to decide if hw pid filtering is used or not. */
37}
38
39const char *flexcop_revision_names[] = {
40 "Unkown chip",
41 "FlexCopII",
42 "FlexCopIIb",
43 "FlexCopIII",
44};
45
46const char *flexcop_device_names[] = {
47 "Unkown device",
48 "Air2PC/AirStar 2 DVB-T",
49 "Air2PC/AirStar 2 ATSC 1st generation",
50 "Air2PC/AirStar 2 ATSC 2nd generation",
51 "Sky2PC/SkyStar 2 DVB-S",
52 "Sky2PC/SkyStar 2 DVB-S (old version)",
53 "Cable2PC/CableStar 2 DVB-C",
54};
55
56const char *flexcop_bus_names[] = {
57 "USB",
58 "PCI",
59};
60
61void flexcop_device_name(struct flexcop_device *fc,const char *prefix,const
62 char *suffix)
63{
64 info("%s '%s' at the '%s' bus controlled by a '%s' %s",prefix,
65 flexcop_device_names[fc->dev_type],flexcop_bus_names[fc->bus_type],
66 flexcop_revision_names[fc->rev],suffix);
67}
diff --git a/drivers/media/dvb/b2c2/flexcop-pci.c b/drivers/media/dvb/b2c2/flexcop-pci.c
new file mode 100644
index 000000000000..ed717c0073d5
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-pci.c
@@ -0,0 +1,381 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-pci.c - covers the PCI part including DMA transfers.
5 *
6 * see flexcop.c for copyright information.
7 */
8
9#define FC_LOG_PREFIX "flexcop-pci"
10#include "flexcop-common.h"
11
12static int enable_pid_filtering = 1;
13module_param(enable_pid_filtering, int, 0444);
14MODULE_PARM_DESC(enable_pid_filtering, "enable hardware pid filtering: supported values: 0 (fullts), 1");
15
16#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
17#define dprintk(level,args...) \
18 do { if ((debug & level)) printk(args); } while (0)
19#define DEBSTATUS ""
20#else
21#define dprintk(level,args...)
22#define DEBSTATUS " (debugging is not enabled)"
23#endif
24
25#define deb_info(args...) dprintk(0x01,args)
26#define deb_reg(args...) dprintk(0x02,args)
27#define deb_ts(args...) dprintk(0x04,args)
28#define deb_irq(args...) dprintk(0x08,args)
29
30static int debug = 0;
31module_param(debug, int, 0644);
32MODULE_PARM_DESC(debug, "set debug level (1=info,2=regs,4=TS,8=irqdma (|-able))." DEBSTATUS);
33
34#define DRIVER_VERSION "0.1"
35#define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV PCI Driver"
36#define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de>"
37
38struct flexcop_pci {
39 struct pci_dev *pdev;
40
41#define FC_PCI_INIT 0x01
42#define FC_PCI_DMA_INIT 0x02
43 int init_state;
44
45 void __iomem *io_mem;
46 u32 irq;
47/* buffersize (at least for DMA1, need to be % 188 == 0,
48 * this logic is required */
49#define FC_DEFAULT_DMA1_BUFSIZE (1280 * 188)
50#define FC_DEFAULT_DMA2_BUFSIZE (10 * 188)
51 struct flexcop_dma dma[2];
52
53 int active_dma1_addr; /* 0 = addr0 of dma1; 1 = addr1 of dma1 */
54 u32 last_dma1_cur_pos; /* position of the pointer last time the timer/packet irq occured */
55 int count;
56
57 spinlock_t irq_lock;
58
59 struct flexcop_device *fc_dev;
60};
61
62static int lastwreg,lastwval,lastrreg,lastrval;
63
64static flexcop_ibi_value flexcop_pci_read_ibi_reg (struct flexcop_device *fc, flexcop_ibi_register r)
65{
66 struct flexcop_pci *fc_pci = fc->bus_specific;
67 flexcop_ibi_value v;
68 v.raw = readl(fc_pci->io_mem + r);
69
70 if (lastrreg != r || lastrval != v.raw) {
71 lastrreg = r; lastrval = v.raw;
72 deb_reg("new rd: %3x: %08x\n",r,v.raw);
73 }
74
75 return v;
76}
77
78static int flexcop_pci_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register r, flexcop_ibi_value v)
79{
80 struct flexcop_pci *fc_pci = fc->bus_specific;
81
82 if (lastwreg != r || lastwval != v.raw) {
83 lastwreg = r; lastwval = v.raw;
84 deb_reg("new wr: %3x: %08x\n",r,v.raw);
85 }
86
87 writel(v.raw, fc_pci->io_mem + r);
88 return 0;
89}
90
91/* When PID filtering is turned on, we use the timer IRQ, because small amounts
92 * of data need to be passed to the user space instantly as well. When PID
93 * filtering is turned off, we use the page-change-IRQ */
94static irqreturn_t flexcop_pci_irq(int irq, void *dev_id, struct pt_regs *regs)
95{
96 struct flexcop_pci *fc_pci = dev_id;
97 struct flexcop_device *fc = fc_pci->fc_dev;
98 flexcop_ibi_value v = fc->read_ibi_reg(fc,irq_20c);
99 irqreturn_t ret = IRQ_HANDLED;
100
101 spin_lock_irq(&fc_pci->irq_lock);
102
103 if (v.irq_20c.DMA1_IRQ_Status == 1) {
104 if (fc_pci->active_dma1_addr == 0)
105 flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr0,fc_pci->dma[0].size / 188);
106 else
107 flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr1,fc_pci->dma[0].size / 188);
108
109 deb_irq("page change to page: %d\n",!fc_pci->active_dma1_addr);
110 fc_pci->active_dma1_addr = !fc_pci->active_dma1_addr;
111 } else if (v.irq_20c.DMA1_Timer_Status == 1) {
112 /* for the timer IRQ we only can use buffer dmx feeding, because we don't have
113 * complete TS packets when reading from the DMA memory */
114 dma_addr_t cur_addr =
115 fc->read_ibi_reg(fc,dma1_008).dma_0x8.dma_cur_addr << 2;
116 u32 cur_pos = cur_addr - fc_pci->dma[0].dma_addr0;
117
118 deb_irq("irq: %08x cur_addr: %08x: cur_pos: %08x, last_cur_pos: %08x ",
119 v.raw,cur_addr,cur_pos,fc_pci->last_dma1_cur_pos);
120
121 /* buffer end was reached, restarted from the beginning
122 * pass the data from last_cur_pos to the buffer end to the demux
123 */
124 if (cur_pos < fc_pci->last_dma1_cur_pos) {
125 deb_irq(" end was reached: passing %d bytes ",(fc_pci->dma[0].size*2 - 1) - fc_pci->last_dma1_cur_pos);
126 flexcop_pass_dmx_data(fc_pci->fc_dev,
127 fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos,
128 (fc_pci->dma[0].size*2) - fc_pci->last_dma1_cur_pos);
129 fc_pci->last_dma1_cur_pos = 0;
130 fc_pci->count = 0;
131 }
132
133 if (cur_pos > fc_pci->last_dma1_cur_pos) {
134 deb_irq(" passing %d bytes ",cur_pos - fc_pci->last_dma1_cur_pos);
135 flexcop_pass_dmx_data(fc_pci->fc_dev,
136 fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos,
137 cur_pos - fc_pci->last_dma1_cur_pos);
138 }
139 deb_irq("\n");
140
141 fc_pci->last_dma1_cur_pos = cur_pos;
142 } else
143 ret = IRQ_NONE;
144
145 spin_unlock_irq(&fc_pci->irq_lock);
146
147/* packet count would be ideal for hw filtering, but it isn't working. Either
148 * the data book is wrong, or I'm unable to read it correctly */
149
150/* if (v.irq_20c.DMA1_Size_IRQ_Status == 1) { packet counter */
151
152 return ret;
153}
154
155static int flexcop_pci_stream_control(struct flexcop_device *fc, int onoff)
156{
157 struct flexcop_pci *fc_pci = fc->bus_specific;
158 if (onoff) {
159 flexcop_dma_config(fc,&fc_pci->dma[0],FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1);
160 flexcop_dma_config(fc,&fc_pci->dma[1],FC_DMA_2,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1);
161 flexcop_dma_config_timer(fc,FC_DMA_1,1);
162
163 if (fc_pci->fc_dev->pid_filtering) {
164 fc_pci->last_dma1_cur_pos = 0;
165 flexcop_dma_control_timer_irq(fc,FC_DMA_1,1);
166 } else {
167 fc_pci->active_dma1_addr = 0;
168 flexcop_dma_control_size_irq(fc,FC_DMA_1,1);
169 }
170
171/* flexcop_dma_config_packet_count(fc,FC_DMA_1,0xc0);
172 flexcop_dma_control_packet_irq(fc,FC_DMA_1,1); */
173
174 deb_irq("irqs enabled\n");
175 } else {
176 if (fc_pci->fc_dev->pid_filtering)
177 flexcop_dma_control_timer_irq(fc,FC_DMA_1,0);
178 else
179 flexcop_dma_control_size_irq(fc,FC_DMA_1,0);
180
181// flexcop_dma_control_packet_irq(fc,FC_DMA_1,0);
182 deb_irq("irqs disabled\n");
183 }
184
185 return 0;
186}
187
188static int flexcop_pci_dma_init(struct flexcop_pci *fc_pci)
189{
190 int ret;
191 if ((ret = flexcop_dma_allocate(fc_pci->pdev,&fc_pci->dma[0],FC_DEFAULT_DMA1_BUFSIZE)) != 0)
192 return ret;
193
194 if ((ret = flexcop_dma_allocate(fc_pci->pdev,&fc_pci->dma[1],FC_DEFAULT_DMA2_BUFSIZE)) != 0)
195 goto dma1_free;
196
197 flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_MEDIA | FC_SRAM_DEST_NET, FC_SRAM_DEST_TARGET_DMA1);
198 flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_DMA2);
199
200 fc_pci->init_state |= FC_PCI_DMA_INIT;
201 goto success;
202dma1_free:
203 flexcop_dma_free(&fc_pci->dma[0]);
204
205success:
206 return ret;
207}
208
209static void flexcop_pci_dma_exit(struct flexcop_pci *fc_pci)
210{
211 if (fc_pci->init_state & FC_PCI_DMA_INIT) {
212 flexcop_dma_free(&fc_pci->dma[0]);
213 flexcop_dma_free(&fc_pci->dma[1]);
214 }
215 fc_pci->init_state &= ~FC_PCI_DMA_INIT;
216}
217
218static int flexcop_pci_init(struct flexcop_pci *fc_pci)
219{
220 int ret;
221 u8 card_rev;
222
223 pci_read_config_byte(fc_pci->pdev, PCI_CLASS_REVISION, &card_rev);
224 info("card revision %x", card_rev);
225
226 if ((ret = pci_enable_device(fc_pci->pdev)) != 0)
227 return ret;
228
229 pci_set_master(fc_pci->pdev);
230
231 /* enable interrupts */
232 // pci_write_config_dword(pdev, 0x6c, 0x8000);
233
234 if ((ret = pci_request_regions(fc_pci->pdev, DRIVER_NAME)) != 0)
235 goto err_pci_disable_device;
236
237 fc_pci->io_mem = pci_iomap(fc_pci->pdev, 0, 0x800);
238
239 if (!fc_pci->io_mem) {
240 err("cannot map io memory\n");
241 ret = -EIO;
242 goto err_pci_release_regions;
243 }
244
245 pci_set_drvdata(fc_pci->pdev, fc_pci);
246
247 if ((ret = request_irq(fc_pci->pdev->irq, flexcop_pci_irq,
248 SA_SHIRQ, DRIVER_NAME, fc_pci)) != 0)
249 goto err_pci_iounmap;
250
251 spin_lock_init(&fc_pci->irq_lock);
252
253 fc_pci->init_state |= FC_PCI_INIT;
254 goto success;
255
256err_pci_iounmap:
257 pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
258 pci_set_drvdata(fc_pci->pdev, NULL);
259err_pci_release_regions:
260 pci_release_regions(fc_pci->pdev);
261err_pci_disable_device:
262 pci_disable_device(fc_pci->pdev);
263
264success:
265 return ret;
266}
267
268static void flexcop_pci_exit(struct flexcop_pci *fc_pci)
269{
270 if (fc_pci->init_state & FC_PCI_INIT) {
271 free_irq(fc_pci->pdev->irq, fc_pci);
272 pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
273 pci_set_drvdata(fc_pci->pdev, NULL);
274 pci_release_regions(fc_pci->pdev);
275 pci_disable_device(fc_pci->pdev);
276 }
277 fc_pci->init_state &= ~FC_PCI_INIT;
278}
279
280
281static int flexcop_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
282{
283 struct flexcop_device *fc;
284 struct flexcop_pci *fc_pci;
285 int ret = -ENOMEM;
286
287 if ((fc = flexcop_device_kmalloc(sizeof(struct flexcop_pci))) == NULL) {
288 err("out of memory\n");
289 return -ENOMEM;
290 }
291
292/* general flexcop init */
293 fc_pci = fc->bus_specific;
294 fc_pci->fc_dev = fc;
295
296 fc->read_ibi_reg = flexcop_pci_read_ibi_reg;
297 fc->write_ibi_reg = flexcop_pci_write_ibi_reg;
298 fc->i2c_request = flexcop_i2c_request;
299 fc->get_mac_addr = flexcop_eeprom_check_mac_addr;
300
301 fc->stream_control = flexcop_pci_stream_control;
302
303 if (enable_pid_filtering)
304 info("will use the HW PID filter.");
305 else
306 info("will pass the complete TS to the demuxer.");
307
308 fc->pid_filtering = enable_pid_filtering;
309 fc->bus_type = FC_PCI;
310
311 fc->dev = &pdev->dev;
312 fc->owner = THIS_MODULE;
313
314/* bus specific part */
315 fc_pci->pdev = pdev;
316 if ((ret = flexcop_pci_init(fc_pci)) != 0)
317 goto err_kfree;
318
319/* init flexcop */
320 if ((ret = flexcop_device_initialize(fc)) != 0)
321 goto err_pci_exit;
322
323/* init dma */
324 if ((ret = flexcop_pci_dma_init(fc_pci)) != 0)
325 goto err_fc_exit;
326
327 goto success;
328err_fc_exit:
329 flexcop_device_exit(fc);
330err_pci_exit:
331 flexcop_pci_exit(fc_pci);
332err_kfree:
333 flexcop_device_kfree(fc);
334success:
335 return ret;
336}
337
338/* in theory every _exit function should be called exactly two times,
339 * here and in the bail-out-part of the _init-function
340 */
341static void flexcop_pci_remove(struct pci_dev *pdev)
342{
343 struct flexcop_pci *fc_pci = pci_get_drvdata(pdev);
344
345 flexcop_pci_dma_exit(fc_pci);
346 flexcop_device_exit(fc_pci->fc_dev);
347 flexcop_pci_exit(fc_pci);
348 flexcop_device_kfree(fc_pci->fc_dev);
349}
350
351static struct pci_device_id flexcop_pci_tbl[] = {
352 { PCI_DEVICE(0x13d0, 0x2103) },
353/* { PCI_DEVICE(0x13d0, 0x2200) }, PCI FlexCopIII ? */
354 { },
355};
356
357MODULE_DEVICE_TABLE(pci, flexcop_pci_tbl);
358
359static struct pci_driver flexcop_pci_driver = {
360 .name = "Technisat/B2C2 FlexCop II/IIb/III PCI",
361 .id_table = flexcop_pci_tbl,
362 .probe = flexcop_pci_probe,
363 .remove = flexcop_pci_remove,
364};
365
366static int __init flexcop_pci_module_init(void)
367{
368 return pci_register_driver(&flexcop_pci_driver);
369}
370
371static void __exit flexcop_pci_module_exit(void)
372{
373 pci_unregister_driver(&flexcop_pci_driver);
374}
375
376module_init(flexcop_pci_module_init);
377module_exit(flexcop_pci_module_exit);
378
379MODULE_AUTHOR(DRIVER_AUTHOR);
380MODULE_DESCRIPTION(DRIVER_NAME);
381MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/b2c2/flexcop-reg.h b/drivers/media/dvb/b2c2/flexcop-reg.h
new file mode 100644
index 000000000000..75b50f21afe6
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-reg.h
@@ -0,0 +1,702 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-reg.h - register abstraction for FlexCopII, FlexCopIIb and FlexCopIII
5 *
6 * see flexcop.c for copyright information.
7 */
8#ifndef __FLEXCOP_REG_H__
9#define __FLEXCOP_REG_H__
10
11
12typedef enum {
13 FLEXCOP_UNK = 0,
14 FLEXCOP_II,
15 FLEXCOP_IIB,
16 FLEXCOP_III,
17} flexcop_revision_t;
18
19extern const char *flexcop_revision_names[];
20
21typedef enum {
22 FC_UNK = 0,
23 FC_AIR_DVB,
24 FC_AIR_ATSC1,
25 FC_AIR_ATSC2,
26 FC_SKY,
27 FC_SKY_OLD,
28 FC_CABLE,
29} flexcop_device_type_t;
30
31typedef enum {
32 FC_USB = 0,
33 FC_PCI,
34} flexcop_bus_t;
35
36extern const char *flexcop_device_names[];
37
38/* FlexCop IBI Registers */
39
40/* flexcop_ibi_reg - a huge union representing the register structure */
41typedef union {
42 u32 raw;
43
44/* DMA 0x000 to 0x01c
45 * DMA1 0x000 to 0x00c
46 * DMA2 0x010 to 0x01c
47 */
48 struct {
49 u32 dma_0start : 1; /* set: data will be delivered to dma1_address0 */
50 u32 dma_0No_update : 1; /* set: dma1_cur_address will be updated, unset: no update */
51 u32 dma_address0 :30; /* physical/virtual host memory address0 DMA */
52 } dma_0x0;
53
54 struct {
55 u32 DMA_maxpackets : 8; /* (remapped) PCI DMA1 Packet Count Interrupt. This variable
56 is able to be read and written while bit(1) of register
57 0x00c (remap_enable) is set. This variable represents
58 the number of packets that will be transmitted to the PCI
59 host using PCI DMA1 before an interrupt to the PCI is
60 asserted. This functionality may be enabled using bit(20)
61 of register 0x208. N=0 disables the IRQ. */
62 u32 dma_addr_size :24; /* size of memory buffer in DWORDs (bytesize / 4) for DMA */
63 } dma_0x4_remap;
64
65 struct {
66 u32 dma1timer : 7; /* reading PCI DMA1 timer ... when remap_enable is 0 */
67 u32 unused : 1;
68 u32 dma_addr_size :24;
69 } dma_0x4_read;
70
71 struct {
72 u32 unused : 1;
73 u32 dmatimer : 7; /* writing PCI DMA1 timer ... when remap_enable is 0 */
74 u32 dma_addr_size :24;
75 } dma_0x4_write;
76
77 struct {
78 u32 unused : 2;
79 u32 dma_cur_addr :30; /* current physical host memory address pointer for DMA */
80 } dma_0x8;
81
82 struct {
83 u32 dma_1start : 1; /* set: data will be delivered to dma_address1, when dma_address0 is full */
84 u32 remap_enable : 1; /* remap enable for 0x0x4(7:0) */
85 u32 dma_address1 :30; /* Physical/virtual address 1 on DMA */
86 } dma_0xc;
87
88/* Two-wire Serial Master and Clock 0x100-0x110 */
89 struct {
90// u32 slave_transmitter : 1; /* ???*/
91 u32 chipaddr : 7; /* two-line serial address of the target slave */
92 u32 reserved1 : 1;
93 u32 baseaddr : 8; /* address of the location of the read/write operation */
94 u32 data1_reg : 8; /* first byte in two-line serial read/write operation */
95 u32 working_start : 1; /* when doing a write operation this indicator is 0 when ready
96 * set to 1 when doing a write operation */
97 u32 twoWS_rw : 1; /* read/write indicator (1 = read, 0 write) */
98 u32 total_bytes : 2; /* number of data bytes in each two-line serial transaction (0 = 1 byte, 11 = 4byte)*/
99 u32 twoWS_port_reg : 2; /* port selection: 01 - Front End/Demod, 10 - EEPROM, 11 - Tuner */
100 u32 no_base_addr_ack_error : 1; /* writing: write-req: frame is produced w/o baseaddr, read-req: read-cycles w/o
101 * preceding address assignment write frame
102 * ACK_ERROR = 1 when no ACK from slave in the last transaction */
103 u32 st_done : 1; /* indicator for transaction is done */
104 } tw_sm_c_100;
105
106 struct {
107 u32 data2_reg : 8; /* 2nd data byte */
108 u32 data3_reg : 8; /* 3rd data byte */
109 u32 data4_reg : 8; /* 4th data byte */
110 u32 exlicit_stops : 1; /* when set, transactions are produced w/o trailing STOP flag, then send isolated STOP flags */
111 u32 force_stop : 1; /* isolated stop flag */
112 u32 unused : 6;
113 } tw_sm_c_104;
114
115/* Clock. The register allows the FCIII to convert an incoming Master clock
116 * (MCLK) signal into a lower frequency clock through the use of a LowCounter
117 * (TLO) and a High- Counter (THI). The time counts for THI and TLO are
118 * measured in MCLK; each count represents 4 MCLK input clock cycles.
119 *
120 * The default output for port #1 is set for Front End Demod communication. (0x108)
121 * The default output for port #2 is set for EEPROM communication. (0x10c)
122 * The default output for port #3 is set for Tuner communication. (0x110)
123 */
124 struct {
125 u32 thi1 : 6; /* Thi for port #1 (def: 100110b; 38) */
126 u32 reserved1 : 2;
127 u32 tlo1 : 5; /* Tlo for port #1 (def: 11100b; 28) */
128 u32 reserved2 :19;
129 } tw_sm_c_108;
130
131 struct {
132 u32 thi1 : 6; /* Thi for port #2 (def: 111001b; 57) */
133 u32 reserved1 : 2;
134 u32 tlo1 : 5; /* Tlo for port #2 (def: 11100b; 28) */
135 u32 reserved2 :19;
136 } tw_sm_c_10c;
137
138 struct {
139 u32 thi1 : 6; /* Thi for port #3 (def: 111001b; 57) */
140 u32 reserved1 : 2;
141 u32 tlo1 : 5; /* Tlo for port #3 (def: 11100b; 28) */
142 u32 reserved2 :19;
143 } tw_sm_c_110;
144
145/* LNB Switch Frequency 0x200
146 * Clock that creates the LNB switch tone. The default is set to have a fixed
147 * low output (not oscillating) to the LNB_CTL line.
148 */
149 struct {
150 u32 LNB_CTLHighCount_sig :15; /* It is the number of pre-scaled clock cycles that will be low. */
151 u32 LNB_CTLLowCount_sig :15; /* For example, to obtain a 22KHz output given a 45 Mhz Master
152 Clock signal (MCLK), set PreScalar=01 and LowCounter value to 0x1ff. */
153 u32 LNB_CTLPrescaler_sig : 2; /* pre-scaler divides MCLK: 00 (no division), 01 by 2, 10 by 4, 11 by 12 */
154 } lnb_switch_freq_200;
155
156/* ACPI, Peripheral Reset, LNB Polarity
157 * ACPI power conservation mode, LNB polarity selection (low or high voltage),
158 * and peripheral reset.
159 */
160 struct {
161 u32 ACPI1_sig : 1; /* turn of the power of tuner and LNB, not implemented in FCIII */
162 u32 ACPI3_sig : 1; /* turn of power of the complete satelite receiver board (except FCIII) */
163 u32 LNB_L_H_sig : 1; /* low or high voltage for LNB. (0 = low, 1 = high) */
164 u32 Per_reset_sig : 1; /* misc. init reset (default: 1), to reset set to low and back to high */
165 u32 reserved :20;
166 u32 Rev_N_sig_revision_hi : 4;/* 0xc in case of FCIII */
167 u32 Rev_N_sig_reserved1 : 2;
168 u32 Rev_N_sig_caps : 1; /* if 1, FCIII has 32 PID- and MAC-filters and is capable of IP multicast */
169 u32 Rev_N_sig_reserved2 : 1;
170 } misc_204;
171
172/* Control and Status 0x208 to 0x21c */
173/* Gross enable and disable control */
174 struct {
175 u32 Stream1_filter_sig : 1; /* Stream1 PID filtering */
176 u32 Stream2_filter_sig : 1; /* Stream2 PID filtering */
177 u32 PCR_filter_sig : 1; /* PCR PID filter */
178 u32 PMT_filter_sig : 1; /* PMT PID filter */
179
180 u32 EMM_filter_sig : 1; /* EMM PID filter */
181 u32 ECM_filter_sig : 1; /* ECM PID filter */
182 u32 Null_filter_sig : 1; /* Filters null packets, PID=0x1fff. */
183 u32 Mask_filter_sig : 1; /* mask PID filter */
184
185 u32 WAN_Enable_sig : 1; /* WAN output line through V8 memory space is activated. */
186 u32 WAN_CA_Enable_sig : 1; /* not in FCIII */
187 u32 CA_Enable_sig : 1; /* not in FCIII */
188 u32 SMC_Enable_sig : 1; /* CI stream data (CAI) goes directly to the smart card intf (opposed IBI 0x600 or SC-cmd buf). */
189
190 u32 Per_CA_Enable_sig : 1; /* not in FCIII */
191 u32 Multi2_Enable_sig : 1; /* ? */
192 u32 MAC_filter_Mode_sig : 1; /* (MAC_filter_enable) Globally enables MAC filters for Net PID filteres. */
193 u32 Rcv_Data_sig : 1; /* PID filtering module enable. When this bit is a one, the PID filter will
194 examine and process packets according to all other (individual) PID
195 filtering controls. If it a zero, no packet processing of any kind will
196 take place. All data from the tuner will be thrown away. */
197
198 u32 DMA1_IRQ_Enable_sig : 1; /* When set, a DWORD counter is enabled on PCI DMA1 that asserts the PCI
199 * interrupt after the specified count for filling the buffer. */
200 u32 DMA1_Timer_Enable_sig : 1; /* When set, a timer is enabled on PCI DMA1 that asserts the PCI interrupt
201 after a specified amount of time. */
202 u32 DMA2_IRQ_Enable_sig : 1; /* same as DMA1_IRQ_Enable_sig but for DMA2 */
203 u32 DMA2_Timer_Enable_sig : 1; /* same as DMA1_Timer_Enable_sig but for DMA2 */
204
205 u32 DMA1_Size_IRQ_Enable_sig : 1; /* When set, a packet count detector is enabled on PCI DMA1 that asserts the PCI interrupt. */
206 u32 DMA2_Size_IRQ_Enable_sig : 1; /* When set, a packet count detector is enabled on PCI DMA2 that asserts the PCI interrupt. */
207 u32 Mailbox_from_V8_Enable_sig: 1; /* When set, writes to the mailbox register produce an interrupt to the
208 PCI host to indicate that mailbox data is available. */
209
210 u32 unused : 9;
211 } ctrl_208;
212
213/* General status. When a PCI interrupt occurs, this register is read to
214 * discover the reason for the interrupt.
215 */
216 struct {
217 u32 DMA1_IRQ_Status : 1; /* When set(1) the DMA1 counter had generated an IRQ. Read Only. */
218 u32 DMA1_Timer_Status : 1; /* When set(1) the DMA1 timer had generated an IRQ. Read Only. */
219 u32 DMA2_IRQ_Status : 1; /* When set(1) the DMA2 counter had generated an IRQ. Read Only. */
220 u32 DMA2_Timer_Status : 1; /* When set(1) the DMA2 timer had generated an IRQ. Read Only. */
221 u32 DMA1_Size_IRQ_Status : 1; /* (Read only). This register is read after an interrupt to */
222 u32 DMA2_Size_IRQ_Status : 1; /* find out why we had an IRQ. Reading this register will clear this bit. Packet count*/
223 u32 Mailbox_from_V8_Status_sig: 1; /* Same as above. Reading this register will clear this bit. */
224 u32 Data_receiver_error : 1; /* 1 indicate an error in the receiver Front End (Tuner module) */
225 u32 Continuity_error_flag : 1; /* 1 indicates a continuity error in the TS stream. */
226 u32 LLC_SNAP_FLAG_set : 1; /* 1 indicates that the LCC_SNAP_FLAG was set. */
227 u32 Transport_Error : 1; /* When set indicates that an unexpected packet was received. */
228 u32 reserved :21;
229 } irq_20c;
230
231
232/* Software reset register */
233 struct {
234 u32 reset_blocks : 8; /* Enabled when Block_reset_enable = 0xB2 and 0x208 bits 15:8 = 0x00.
235 Each bit location represents a 0x100 block of registers. Writing
236 a one in a bit location resets that block of registers and the logic
237 that it controls. */
238 u32 Block_reset_enable : 8; /* This variable is set to 0xB2 when the register is written. */
239 u32 Special_controls :16; /* Asserts Reset_V8 => 0xC258; Turns on pci encryption => 0xC25A;
240 Turns off pci encryption => 0xC259 Note: pci_encryption default
241 at power-up is ON. */
242 } sw_reset_210;
243
244 struct {
245 u32 vuart_oe_sig : 1; /* When clear, the V8 processor has sole control of the serial UART
246 (RS-232 Smart Card interface). When set, the IBI interface
247 defined by register 0x600 controls the serial UART. */
248 u32 v2WS_oe_sig : 1; /* When clear, the V8 processor has direct control of the Two-line
249 Serial Master EEPROM target. When set, the Two-line Serial Master
250 EEPROM target interface is controlled by IBI register 0x100. */
251 u32 halt_V8_sig : 1; /* When set, contiguous wait states are applied to the V8-space
252 bus masters. Once this signal is cleared, normal V8-space
253 operations resume. */
254 u32 section_pkg_enable_sig: 1; /* When set, this signal enables the front end translation circuitry
255 to process section packed transport streams. */
256 u32 s2p_sel_sig : 1; /* Serial to parallel conversion. When set, polarized transport data
257 within the FlexCop3 front end circuitry is converted from a serial
258 stream into parallel data before downstream processing otherwise
259 interprets the data. */
260 u32 unused1 : 3;
261 u32 polarity_PS_CLK_sig: 1; /* This signal is used to invert the input polarity of the tranport
262 stream CLOCK signal before any processing occurs on the transport
263 stream within FlexCop3. */
264 u32 polarity_PS_VALID_sig: 1; /* This signal is used to invert the input polarity of the tranport
265 stream VALID signal before any processing occurs on the transport
266 stream within FlexCop3. */
267 u32 polarity_PS_SYNC_sig: 1; /* This signal is used to invert the input polarity of the tranport
268 stream SYNC signal before any processing occurs on the transport
269 stream within FlexCop3. */
270 u32 polarity_PS_ERR_sig: 1; /* This signal is used to invert the input polarity of the tranport
271 stream ERROR signal before any processing occurs on the transport
272 stream within FlexCop3. */
273 u32 unused2 :20;
274 } misc_214;
275
276/* Mailbox from V8 to host */
277 struct {
278 u32 Mailbox_from_V8 :32; /* When this register is written by either the V8 processor or by an
279 end host, an interrupt is generated to the PCI host to indicate
280 that mailbox data is available. Reading register 20c will clear
281 the IRQ. */
282 } mbox_v8_to_host_218;
283
284/* Mailbox from host to v8 Mailbox_to_V8
285 * Mailbox_to_V8 mailbox storage register
286 * used to send messages from PCI to V8. Writing to this register will send an
287 * IRQ to the V8. Then it can read the data from here. Reading this register
288 * will clear the IRQ. If the V8 is halted and bit 31 of this register is set,
289 * then this register is used instead as a direct interface to access the
290 * V8space memory.
291 */
292 struct {
293 u32 sysramaccess_data : 8; /* Data byte written or read from the specified address in V8 SysRAM. */
294 u32 sysramaccess_addr :15; /* 15 bit address used to access V8 Sys-RAM. */
295 u32 unused : 7;
296 u32 sysramaccess_write: 1; /* Write flag used to latch data into the V8 SysRAM. */
297 u32 sysramaccess_busmuster: 1; /* Setting this bit when the V8 is halted at 0x214 Bit(2) allows
298 this IBI register interface to directly drive the V8-space memory. */
299 } mbox_host_to_v8_21c;
300
301
302/* PIDs, Translation Bit, SMC Filter Select 0x300 to 0x31c */
303 struct {
304 u32 Stream1_PID :13; /* Primary use is receiving Net data, so these 13 bits normally
305 hold the PID value for the desired network stream. */
306 u32 Stream1_trans : 1; /* When set, Net translation will take place for Net data ferried in TS packets. */
307 u32 MAC_Multicast_filter : 1; /* When clear, multicast MAC filtering is not allowed for Stream1 and PID_n filters. */
308 u32 debug_flag_pid_saved : 1;
309 u32 Stream2_PID :13; /* 13 bits for Stream 2 PID filter value. General use. */
310 u32 Stream2_trans : 1; /* When set Tables/CAI translation will take place for the data ferried in
311 Stream2_PID TS packets. */
312 u32 debug_flag_write_status00 : 1;
313 u32 debug_fifo_problem : 1;
314 } pid_filter_300;
315
316 struct {
317 u32 PCR_PID :13; /* PCR stream PID filter value. Primary use is Program Clock Reference stream filtering. */
318 u32 PCR_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
319 u32 debug_overrun3 : 1;
320 u32 debug_overrun2 : 1;
321 u32 PMT_PID :13; /* stream PID filter value. Primary use is Program Management Table segment filtering. */
322 u32 PMT_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
323 u32 reserved : 2;
324 } pid_filter_304;
325
326 struct {
327 u32 EMM_PID :13; /* EMM PID filter value. Primary use is Entitlement Management Messaging for
328 conditional access-related data. */
329 u32 EMM_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
330 u32 EMM_filter_4 : 1; /* When set will pass only EMM data possessing the same ID code as the
331 first four bytes (32 bits) of the end-user s 6-byte Smart Card ID number Select */
332 u32 EMM_filter_6 : 1; /* When set will pass only EMM data possessing the same 6-byte code as the end-users
333 complete 6-byte Smart Card ID number. */
334 u32 ECM_PID :13; /* ECM PID filter value. Primary use is Entitlement Control Messaging for conditional
335 access-related data. */
336 u32 ECM_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
337 u32 reserved : 2;
338 } pid_filter_308;
339
340 struct {
341 u32 Group_PID :13; /* PID value for group filtering. */
342 u32 Group_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
343 u32 unused1 : 2;
344 u32 Group_mask :13; /* Mask value used in logical "and" equation that defines group filtering */
345 u32 unused2 : 3;
346 } pid_filter_30c_ext_ind_0_7;
347
348 struct {
349 u32 net_master_read :17;
350 u32 unused :15;
351 } pid_filter_30c_ext_ind_1;
352
353 struct {
354 u32 net_master_write :17;
355 u32 unused :15;
356 } pid_filter_30c_ext_ind_2;
357
358 struct {
359 u32 next_net_master_write :17;
360 u32 unused :15;
361 } pid_filter_30c_ext_ind_3;
362
363 struct {
364 u32 unused1 : 1;
365 u32 state_write :10;
366 u32 reserved1 : 6; /* default: 000100 */
367 u32 stack_read :10;
368 u32 reserved2 : 5; /* default: 00100 */
369 } pid_filter_30c_ext_ind_4;
370
371 struct {
372 u32 stack_cnt :10;
373 u32 unused :22;
374 } pid_filter_30c_ext_ind_5;
375
376 struct {
377 u32 pid_fsm_save_reg0 : 2;
378 u32 pid_fsm_save_reg1 : 2;
379 u32 pid_fsm_save_reg2 : 2;
380 u32 pid_fsm_save_reg3 : 2;
381 u32 pid_fsm_save_reg4 : 2;
382 u32 pid_fsm_save_reg300 : 2;
383 u32 write_status1 : 2;
384 u32 write_status4 : 2;
385 u32 data_size_reg :12;
386 u32 unused : 4;
387 } pid_filter_30c_ext_ind_6;
388
389 struct {
390 u32 index_reg : 5; /* (Index pointer) Points at an internal PIDn register. A binary code
391 representing one of 32 internal PIDn registers as well as its
392 corresponding internal MAC_lown register. */
393 u32 extra_index_reg : 3; /* This vector is used to select between sets of debug signals routed to register 0x30c. */
394 u32 AB_select : 1; /* Used in conjunction with 0x31c. read/write to the MAC_highA or MAC_highB register
395 0=MAC_highB register, 1=MAC_highA */
396 u32 pass_alltables : 1; /* 1=Net packets are not filtered against the Network Table ID found in register 0x400.
397 All types of networks (DVB, ATSC, ISDB) are passed. */
398 u32 unused :22;
399 } index_reg_310;
400
401 struct {
402 u32 PID :13; /* PID value */
403 u32 PID_trans : 1; /* translation will take place for packets filtered */
404 u32 PID_enable_bit : 1; /* When set this PID filter is enabled */
405 u32 reserved :17;
406 } pid_n_reg_314;
407
408 struct {
409 u32 A4_byte : 8;
410 u32 A5_byte : 8;
411 u32 A6_byte : 8;
412 u32 Enable_bit : 1; /* enabled (1) or disabled (1) */
413 u32 HighAB_bit : 1; /* use MAC_highA (1) or MAC_highB (0) as MSB */
414 u32 reserved : 6;
415 } mac_low_reg_318;
416
417 struct {
418 u32 A1_byte : 8;
419 u32 A2_byte : 8;
420 u32 A3_byte : 8;
421 u32 reserved : 8;
422 } mac_high_reg_31c;
423
424/* Table, SMCID,MACDestination Filters 0x400 to 0x41c */
425 struct {
426 u32 reserved :16;
427#define fc_data_Tag_ID_DVB 0x3e
428#define fc_data_Tag_ID_ATSC 0x3f
429#define fc_data_Tag_ID_IDSB 0x8b
430 u32 data_Tag_ID :16;
431 } data_tag_400;
432
433 struct {
434 u32 Card_IDbyte6 : 8;
435 u32 Card_IDbyte5 : 8;
436 u32 Card_IDbyte4 : 8;
437 u32 Card_IDbyte3 : 8;
438 } card_id_408;
439
440 struct {
441 u32 Card_IDbyte2 : 8;
442 u32 Card_IDbyte1 : 8;
443 } card_id_40c;
444
445 /* holding the unique mac address of the receiver which houses the FlexCopIII */
446 struct {
447 u32 MAC1 : 8;
448 u32 MAC2 : 8;
449 u32 MAC3 : 8;
450 u32 MAC6 : 8;
451 } mac_address_418;
452
453 struct {
454 u32 MAC7 : 8;
455 u32 MAC8 : 8;
456 u32 reserved : 16;
457 } mac_address_41c;
458
459 struct {
460 u32 transmitter_data_byte : 8;
461 u32 ReceiveDataReady : 1;
462 u32 ReceiveByteFrameError: 1;
463 u32 txbuffempty : 1;
464 u32 reserved :21;
465 } ci_600;
466
467 struct {
468 u32 pi_d : 8;
469 u32 pi_ha :20;
470 u32 pi_rw : 1;
471 u32 pi_component_reg : 3;
472 } pi_604;
473
474 struct {
475 u32 serialReset : 1;
476 u32 oncecycle_read : 1;
477 u32 Timer_Read_req : 1;
478 u32 Timer_Load_req : 1;
479 u32 timer_data : 7;
480 u32 unused : 1; /* ??? not mentioned in data book */
481 u32 Timer_addr : 5;
482 u32 reserved : 3;
483 u32 pcmcia_a_mod_pwr_n : 1;
484 u32 pcmcia_b_mod_pwr_n : 1;
485 u32 config_Done_stat : 1;
486 u32 config_Init_stat : 1;
487 u32 config_Prog_n : 1;
488 u32 config_wr_n : 1;
489 u32 config_cs_n : 1;
490 u32 config_cclk : 1;
491 u32 pi_CiMax_IRQ_n : 1;
492 u32 pi_timeout_status : 1;
493 u32 pi_wait_n : 1;
494 u32 pi_busy_n : 1;
495 } pi_608;
496
497 struct {
498 u32 PID :13;
499 u32 key_enable : 1;
500#define fc_key_code_default 0x1
501#define fc_key_code_even 0x2
502#define fc_key_code_odd 0x3
503 u32 key_code : 2;
504 u32 key_array_col : 3;
505 u32 key_array_row : 5;
506 u32 dvb_en : 1; /* 0=TS bypasses the Descrambler */
507 u32 rw_flag : 1;
508 u32 reserved : 6;
509 } dvb_reg_60c;
510
511/* SRAM and Output Destination 0x700 to 0x714 */
512 struct {
513 u32 sram_addr :15;
514 u32 sram_rw : 1; /* 0=write, 1=read */
515 u32 sram_data : 8;
516 u32 sc_xfer_bit : 1;
517 u32 reserved1 : 3;
518 u32 oe_pin_reg : 1;
519 u32 ce_pin_reg : 1;
520 u32 reserved2 : 1;
521 u32 start_sram_ibi : 1;
522 } sram_ctrl_reg_700;
523
524 struct {
525 u32 net_addr_read :16;
526 u32 net_addr_write :16;
527 } net_buf_reg_704;
528
529 struct {
530 u32 cai_read :11;
531 u32 reserved1 : 5;
532 u32 cai_write :11;
533 u32 reserved2 : 6;
534 u32 cai_cnt : 4;
535 } cai_buf_reg_708;
536
537 struct {
538 u32 cao_read :11;
539 u32 reserved1 : 5;
540 u32 cap_write :11;
541 u32 reserved2 : 6;
542 u32 cao_cnt : 4;
543 } cao_buf_reg_70c;
544
545 struct {
546 u32 media_read :11;
547 u32 reserved1 : 5;
548 u32 media_write :11;
549 u32 reserved2 : 6;
550 u32 media_cnt : 4;
551 } media_buf_reg_710;
552
553 struct {
554 u32 NET_Dest : 2;
555 u32 CAI_Dest : 2;
556 u32 CAO_Dest : 2;
557 u32 MEDIA_Dest : 2;
558 u32 net_ovflow_error : 1;
559 u32 media_ovflow_error : 1;
560 u32 cai_ovflow_error : 1;
561 u32 cao_ovflow_error : 1;
562 u32 ctrl_usb_wan : 1;
563 u32 ctrl_sramdma : 1;
564 u32 ctrl_maximumfill : 1;
565 u32 reserved :17;
566 } sram_dest_reg_714;
567
568 struct {
569 u32 net_cnt :12;
570 u32 reserved1 : 4;
571 u32 net_addr_read : 1;
572 u32 reserved2 : 3;
573 u32 net_addr_write : 1;
574 u32 reserved3 :11;
575 } net_buf_reg_718;
576
577 struct {
578 u32 wan_speed_sig : 2;
579 u32 reserved1 : 6;
580 u32 wan_wait_state : 8;
581 u32 sram_chip : 2;
582 u32 sram_memmap : 2;
583 u32 reserved2 : 4;
584 u32 wan_pkt_frame : 4;
585 u32 reserved3 : 4;
586 } wan_ctrl_reg_71c;
587} flexcop_ibi_value;
588
589extern flexcop_ibi_value ibi_zero;
590
591typedef enum {
592 FC_I2C_PORT_DEMOD = 1,
593 FC_I2C_PORT_EEPROM = 2,
594 FC_I2C_PORT_TUNER = 3,
595} flexcop_i2c_port_t;
596
597typedef enum {
598 FC_WRITE = 0,
599 FC_READ = 1,
600} flexcop_access_op_t;
601
602typedef enum {
603 FC_SRAM_DEST_NET = 1,
604 FC_SRAM_DEST_CAI = 2,
605 FC_SRAM_DEST_CAO = 4,
606 FC_SRAM_DEST_MEDIA = 8
607} flexcop_sram_dest_t;
608
609typedef enum {
610 FC_SRAM_DEST_TARGET_WAN_USB = 0,
611 FC_SRAM_DEST_TARGET_DMA1 = 1,
612 FC_SRAM_DEST_TARGET_DMA2 = 2,
613 FC_SRAM_DEST_TARGET_FC3_CA = 3
614} flexcop_sram_dest_target_t;
615
616typedef enum {
617 FC_SRAM_2_32KB = 0, /* 64KB */
618 FC_SRAM_1_32KB = 1, /* 32KB - default fow FCII */
619 FC_SRAM_1_128KB = 2, /* 128KB */
620 FC_SRAM_1_48KB = 3, /* 48KB - default for FCIII */
621} flexcop_sram_type_t;
622
623typedef enum {
624 FC_WAN_SPEED_4MBITS = 0,
625 FC_WAN_SPEED_8MBITS = 1,
626 FC_WAN_SPEED_12MBITS = 2,
627 FC_WAN_SPEED_16MBITS = 3,
628} flexcop_wan_speed_t;
629
630typedef enum {
631 FC_DMA_1 = 1,
632 FC_DMA_2 = 2,
633} flexcop_dma_index_t;
634
635typedef enum {
636 FC_DMA_SUBADDR_0 = 1,
637 FC_DMA_SUBADDR_1 = 2,
638} flexcop_dma_addr_index_t;
639
640/* names of the particular registers */
641typedef enum {
642 dma1_000 = 0x000,
643 dma1_004 = 0x004,
644 dma1_008 = 0x008,
645 dma1_00c = 0x00c,
646 dma2_010 = 0x010,
647 dma2_014 = 0x014,
648 dma2_018 = 0x018,
649 dma2_01c = 0x01c,
650
651 tw_sm_c_100 = 0x100,
652 tw_sm_c_104 = 0x104,
653 tw_sm_c_108 = 0x108,
654 tw_sm_c_10c = 0x10c,
655 tw_sm_c_110 = 0x110,
656
657 lnb_switch_freq_200 = 0x200,
658 misc_204 = 0x204,
659 ctrl_208 = 0x208,
660 irq_20c = 0x20c,
661 sw_reset_210 = 0x210,
662 misc_214 = 0x214,
663 mbox_v8_to_host_218 = 0x218,
664 mbox_host_to_v8_21c = 0x21c,
665
666 pid_filter_300 = 0x300,
667 pid_filter_304 = 0x304,
668 pid_filter_308 = 0x308,
669 pid_filter_30c = 0x30c,
670 index_reg_310 = 0x310,
671 pid_n_reg_314 = 0x314,
672 mac_low_reg_318 = 0x318,
673 mac_high_reg_31c = 0x31c,
674
675 data_tag_400 = 0x400,
676 card_id_408 = 0x408,
677 card_id_40c = 0x40c,
678 mac_address_418 = 0x418,
679 mac_address_41c = 0x41c,
680
681 ci_600 = 0x600,
682 pi_604 = 0x604,
683 pi_608 = 0x608,
684 dvb_reg_60c = 0x60c,
685
686 sram_ctrl_reg_700 = 0x700,
687 net_buf_reg_704 = 0x704,
688 cai_buf_reg_708 = 0x708,
689 cao_buf_reg_70c = 0x70c,
690 media_buf_reg_710 = 0x710,
691 sram_dest_reg_714 = 0x714,
692 net_buf_reg_718 = 0x718,
693 wan_ctrl_reg_71c = 0x71c,
694} flexcop_ibi_register;
695
696#define flexcop_set_ibi_value(reg,attr,val) { \
697 flexcop_ibi_value v = fc->read_ibi_reg(fc,reg); \
698 v.reg.attr = val; \
699 fc->write_ibi_reg(fc,reg,v); \
700}
701
702#endif
diff --git a/drivers/media/dvb/b2c2/flexcop-sram.c b/drivers/media/dvb/b2c2/flexcop-sram.c
new file mode 100644
index 000000000000..01570ec80962
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-sram.c
@@ -0,0 +1,403 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-sram.c - functions for controlling the SRAM.
5 *
6 * see flexcop.c for copyright information.
7 */
8#include "flexcop.h"
9
10static void flexcop_sram_set_chip (struct flexcop_device *fc, flexcop_sram_type_t type)
11{
12 flexcop_set_ibi_value(wan_ctrl_reg_71c,sram_chip,type);
13}
14
15int flexcop_sram_init(struct flexcop_device *fc)
16{
17 switch (fc->rev) {
18 case FLEXCOP_II:
19 case FLEXCOP_IIB:
20 flexcop_sram_set_chip(fc,FC_SRAM_1_32KB);
21 break;
22 case FLEXCOP_III:
23 flexcop_sram_set_chip(fc,FC_SRAM_1_48KB);
24 break;
25 default:
26 return -EINVAL;
27 }
28 return 0;
29}
30
31int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target)
32{
33 flexcop_ibi_value v;
34
35 v = fc->read_ibi_reg(fc,sram_dest_reg_714);
36
37 if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) {
38 err("SRAM destination target to available on FlexCopII(b)\n");
39 return -EINVAL;
40 }
41
42 deb_sram("sram dest: %x target: %x\n",dest, target);
43
44 if (dest & FC_SRAM_DEST_NET)
45 v.sram_dest_reg_714.NET_Dest = target;
46 if (dest & FC_SRAM_DEST_CAI)
47 v.sram_dest_reg_714.CAI_Dest = target;
48 if (dest & FC_SRAM_DEST_CAO)
49 v.sram_dest_reg_714.CAO_Dest = target;
50 if (dest & FC_SRAM_DEST_MEDIA)
51 v.sram_dest_reg_714.MEDIA_Dest = target;
52
53 fc->write_ibi_reg(fc,sram_dest_reg_714,v);
54 udelay(1000); /* TODO delay really necessary */
55
56 return 0;
57}
58EXPORT_SYMBOL(flexcop_sram_set_dest);
59
60void flexcop_wan_set_speed(struct flexcop_device *fc, flexcop_wan_speed_t s)
61{
62 flexcop_set_ibi_value(wan_ctrl_reg_71c,wan_speed_sig,s);
63}
64EXPORT_SYMBOL(flexcop_wan_set_speed);
65
66void flexcop_sram_ctrl(struct flexcop_device *fc, int usb_wan, int sramdma, int maximumfill)
67{
68 flexcop_ibi_value v = fc->read_ibi_reg(fc,sram_dest_reg_714);
69 v.sram_dest_reg_714.ctrl_usb_wan = usb_wan;
70 v.sram_dest_reg_714.ctrl_sramdma = sramdma;
71 v.sram_dest_reg_714.ctrl_maximumfill = maximumfill;
72 fc->write_ibi_reg(fc,sram_dest_reg_714,v);
73}
74EXPORT_SYMBOL(flexcop_sram_ctrl);
75
76#if 0
77static void flexcop_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
78{
79 int i, retries;
80 u32 command;
81
82 for (i = 0; i < len; i++) {
83 command = bank | addr | 0x04000000 | (*buf << 0x10);
84
85 retries = 2;
86
87 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
88 mdelay(1);
89 retries--;
90 };
91
92 if (retries == 0)
93 printk("%s: SRAM timeout\n", __FUNCTION__);
94
95 write_reg_dw(adapter, 0x700, command);
96
97 buf++;
98 addr++;
99 }
100}
101
102static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
103{
104 int i, retries;
105 u32 command, value;
106
107 for (i = 0; i < len; i++) {
108 command = bank | addr | 0x04008000;
109
110 retries = 10000;
111
112 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
113 mdelay(1);
114 retries--;
115 };
116
117 if (retries == 0)
118 printk("%s: SRAM timeout\n", __FUNCTION__);
119
120 write_reg_dw(adapter, 0x700, command);
121
122 retries = 10000;
123
124 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
125 mdelay(1);
126 retries--;
127 };
128
129 if (retries == 0)
130 printk("%s: SRAM timeout\n", __FUNCTION__);
131
132 value = read_reg_dw(adapter, 0x700) >> 0x10;
133
134 *buf = (value & 0xff);
135
136 addr++;
137 buf++;
138 }
139}
140
141static void sram_write_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
142{
143 u32 bank;
144
145 bank = 0;
146
147 if (adapter->dw_sram_type == 0x20000) {
148 bank = (addr & 0x18000) << 0x0d;
149 }
150
151 if (adapter->dw_sram_type == 0x00000) {
152 if ((addr >> 0x0f) == 0)
153 bank = 0x20000000;
154 else
155 bank = 0x10000000;
156 }
157
158 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len);
159}
160
161static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
162{
163 u32 bank;
164
165 bank = 0;
166
167 if (adapter->dw_sram_type == 0x20000) {
168 bank = (addr & 0x18000) << 0x0d;
169 }
170
171 if (adapter->dw_sram_type == 0x00000) {
172 if ((addr >> 0x0f) == 0)
173 bank = 0x20000000;
174 else
175 bank = 0x10000000;
176 }
177
178 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len);
179}
180
181static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
182{
183 u32 length;
184
185 while (len != 0) {
186 length = len;
187
188 // check if the address range belongs to the same
189 // 32K memory chip. If not, the data is read from
190 // one chip at a time.
191 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
192 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
193 }
194
195 sram_read_chunk(adapter, addr, buf, length);
196
197 addr = addr + length;
198 buf = buf + length;
199 len = len - length;
200 }
201}
202
203static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
204{
205 u32 length;
206
207 while (len != 0) {
208 length = len;
209
210 // check if the address range belongs to the same
211 // 32K memory chip. If not, the data is written to
212 // one chip at a time.
213 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
214 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
215 }
216
217 sram_write_chunk(adapter, addr, buf, length);
218
219 addr = addr + length;
220 buf = buf + length;
221 len = len - length;
222 }
223}
224
225static void sram_set_size(struct adapter *adapter, u32 mask)
226{
227 write_reg_dw(adapter, 0x71c, (mask | (~0x30000 & read_reg_dw(adapter, 0x71c))));
228}
229
230static void sram_init(struct adapter *adapter)
231{
232 u32 tmp;
233
234 tmp = read_reg_dw(adapter, 0x71c);
235
236 write_reg_dw(adapter, 0x71c, 1);
237
238 if (read_reg_dw(adapter, 0x71c) != 0) {
239 write_reg_dw(adapter, 0x71c, tmp);
240
241 adapter->dw_sram_type = tmp & 0x30000;
242
243 ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type);
244
245 } else {
246
247 adapter->dw_sram_type = 0x10000;
248
249 ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type);
250 }
251
252 /* return value is never used? */
253/* return adapter->dw_sram_type; */
254}
255
256static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
257{
258 u8 tmp1, tmp2;
259
260 dprintk("%s: mask = %x, addr = %x\n", __FUNCTION__, mask, addr);
261
262 sram_set_size(adapter, mask);
263 sram_init(adapter);
264
265 tmp2 = 0xa5;
266 tmp1 = 0x4f;
267
268 sram_write(adapter, addr, &tmp2, 1);
269 sram_write(adapter, addr + 4, &tmp1, 1);
270
271 tmp2 = 0;
272
273 mdelay(20);
274
275 sram_read(adapter, addr, &tmp2, 1);
276 sram_read(adapter, addr, &tmp2, 1);
277
278 dprintk("%s: wrote 0xa5, read 0x%2x\n", __FUNCTION__, tmp2);
279
280 if (tmp2 != 0xa5)
281 return 0;
282
283 tmp2 = 0x5a;
284 tmp1 = 0xf4;
285
286 sram_write(adapter, addr, &tmp2, 1);
287 sram_write(adapter, addr + 4, &tmp1, 1);
288
289 tmp2 = 0;
290
291 mdelay(20);
292
293 sram_read(adapter, addr, &tmp2, 1);
294 sram_read(adapter, addr, &tmp2, 1);
295
296 dprintk("%s: wrote 0x5a, read 0x%2x\n", __FUNCTION__, tmp2);
297
298 if (tmp2 != 0x5a)
299 return 0;
300
301 return 1;
302}
303
304static u32 sram_length(struct adapter *adapter)
305{
306 if (adapter->dw_sram_type == 0x10000)
307 return 32768; // 32K
308 if (adapter->dw_sram_type == 0x00000)
309 return 65536; // 64K
310 if (adapter->dw_sram_type == 0x20000)
311 return 131072; // 128K
312
313 return 32768; // 32K
314}
315
316/* FlexcopII can work with 32K, 64K or 128K of external SRAM memory.
317 - for 128K there are 4x32K chips at bank 0,1,2,3.
318 - for 64K there are 2x32K chips at bank 1,2.
319 - for 32K there is one 32K chip at bank 0.
320
321 FlexCop works only with one bank at a time. The bank is selected
322 by bits 28-29 of the 0x700 register.
323
324 bank 0 covers addresses 0x00000-0x07fff
325 bank 1 covers addresses 0x08000-0x0ffff
326 bank 2 covers addresses 0x10000-0x17fff
327 bank 3 covers addresses 0x18000-0x1ffff
328*/
329
330static int flexcop_sram_detect(struct flexcop_device *fc)
331{
332 flexcop_ibi_value r208,r71c_0,vr71c_1;
333
334 r208 = fc->read_ibi_reg(fc, ctrl_208);
335 fc->write_ibi_reg(fc, ctrl_208, ibi_zero);
336
337 r71c_0 = fc->read_ibi_reg(fc, wan_ctrl_reg_71c);
338
339 write_reg_dw(adapter, 0x71c, 1);
340
341 tmp3 = read_reg_dw(adapter, 0x71c);
342
343 dprintk("%s: tmp3 = %x\n", __FUNCTION__, tmp3);
344
345 write_reg_dw(adapter, 0x71c, tmp2);
346
347 // check for internal SRAM ???
348 tmp3--;
349 if (tmp3 != 0) {
350 sram_set_size(adapter, 0x10000);
351 sram_init(adapter);
352 write_reg_dw(adapter, 0x208, tmp);
353
354 dprintk("%s: sram size = 32K\n", __FUNCTION__);
355
356 return 32;
357 }
358
359 if (sram_test_location(adapter, 0x20000, 0x18000) != 0) {
360 sram_set_size(adapter, 0x20000);
361 sram_init(adapter);
362 write_reg_dw(adapter, 0x208, tmp);
363
364 dprintk("%s: sram size = 128K\n", __FUNCTION__);
365
366 return 128;
367 }
368
369 if (sram_test_location(adapter, 0x00000, 0x10000) != 0) {
370 sram_set_size(adapter, 0x00000);
371 sram_init(adapter);
372 write_reg_dw(adapter, 0x208, tmp);
373
374 dprintk("%s: sram size = 64K\n", __FUNCTION__);
375
376 return 64;
377 }
378
379 if (sram_test_location(adapter, 0x10000, 0x00000) != 0) {
380 sram_set_size(adapter, 0x10000);
381 sram_init(adapter);
382 write_reg_dw(adapter, 0x208, tmp);
383
384 dprintk("%s: sram size = 32K\n", __FUNCTION__);
385
386 return 32;
387 }
388
389 sram_set_size(adapter, 0x10000);
390 sram_init(adapter);
391 write_reg_dw(adapter, 0x208, tmp);
392
393 dprintk("%s: SRAM detection failed. Set to 32K \n", __FUNCTION__);
394
395 return 0;
396}
397
398static void sll_detect_sram_size(struct adapter *adapter)
399{
400 sram_detect_for_flex2(adapter);
401}
402
403#endif
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.c b/drivers/media/dvb/b2c2/flexcop-usb.c
new file mode 100644
index 000000000000..0113449abd15
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-usb.c
@@ -0,0 +1,577 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-usb.c - covers the USB part.
5 *
6 * see flexcop.c for copyright information.
7 */
8
9#define FC_LOG_PREFIX "flexcop_usb"
10#include "flexcop-usb.h"
11#include "flexcop-common.h"
12
13/* Version information */
14#define DRIVER_VERSION "0.1"
15#define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV USB Driver"
16#define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de>"
17
18/* debug */
19#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
20#define dprintk(level,args...) \
21 do { if ((debug & level)) { printk(args); } } while (0)
22#define debug_dump(b,l,method) {\
23 int i; \
24 for (i = 0; i < l; i++) method("%02x ", b[i]); \
25 method("\n");\
26}
27
28#define DEBSTATUS ""
29#else
30#define dprintk(level,args...)
31#define debug_dump(b,l,method)
32#define DEBSTATUS " (debugging is not enabled)"
33#endif
34
35static int debug;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "set debugging level (1=info,ts=2,ctrl=4,i2c=8,v8mem=16 (or-able))." DEBSTATUS);
38#undef DEBSTATUS
39
40#define deb_info(args...) dprintk(0x01,args)
41#define deb_ts(args...) dprintk(0x02,args)
42#define deb_ctrl(args...) dprintk(0x04,args)
43#define deb_i2c(args...) dprintk(0x08,args)
44#define deb_v8(args...) dprintk(0x10,args)
45
46/* JLP 111700: we will include the 1 bit gap between the upper and lower 3 bits
47 * in the IBI address, to make the V8 code simpler.
48 * PCI ADDRESS FORMAT: 0x71C -> 0000 0111 0001 1100 (these are the six bits used)
49 * in general: 0000 0HHH 000L LL00
50 * IBI ADDRESS FORMAT: RHHH BLLL
51 *
52 * where R is the read(1)/write(0) bit, B is the busy bit
53 * and HHH and LLL are the two sets of three bits from the PCI address.
54 */
55#define B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(usPCI) (u8) (((usPCI >> 2) & 0x07) + ((usPCI >> 4) & 0x70))
56#define B2C2_FLEX_INTERNALADDR_TO_PCIOFFSET(ucAddr) (u16) (((ucAddr & 0x07) << 2) + ((ucAddr & 0x70) << 4))
57
58/*
59 * DKT 020228
60 * - forget about this VENDOR_BUFFER_SIZE, read and write register
61 * deal with DWORD or 4 bytes, that should be should from now on
62 * - from now on, we don't support anything older than firm 1.00
63 * I eliminated the write register as a 2 trip of writing hi word and lo word
64 * and force this to write only 4 bytes at a time.
65 * NOTE: this should work with all the firmware from 1.00 and newer
66 */
67static int flexcop_usb_readwrite_dw(struct flexcop_device *fc, u16 wRegOffsPCI, u32 *val, u8 read)
68{
69 struct flexcop_usb *fc_usb = fc->bus_specific;
70 u8 request = read ? B2C2_USB_READ_REG : B2C2_USB_WRITE_REG;
71 u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR;
72 u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) | (read ? 0x80 : 0);
73
74 int len = usb_control_msg(fc_usb->udev,
75 read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT,
76 request,
77 request_type, /* 0xc0 read or 0x40 write*/
78 wAddress,
79 0,
80 val,
81 sizeof(u32),
82 B2C2_WAIT_FOR_OPERATION_RDW * HZ);
83
84 if (len != sizeof(u32)) {
85 err("error while %s dword from %d (%d).",read ? "reading" : "writing",
86 wAddress,wRegOffsPCI);
87 return -EIO;
88 }
89 return 0;
90}
91
92/*
93 * DKT 010817 - add support for V8 memory read/write and flash update
94 */
95static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb,
96 flexcop_usb_request_t req, u8 page, u16 wAddress,
97 u8 *pbBuffer,u32 buflen)
98{
99// u8 dwRequestType;
100 u8 request_type = USB_TYPE_VENDOR;
101 u16 wIndex;
102 int nWaitTime,pipe,len;
103
104 wIndex = page << 8;
105
106 switch (req) {
107 case B2C2_USB_READ_V8_MEM:
108 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ;
109 request_type |= USB_DIR_IN;
110// dwRequestType = (u8) RTYPE_READ_V8_MEMORY;
111 pipe = B2C2_USB_CTRL_PIPE_IN;
112 break;
113 case B2C2_USB_WRITE_V8_MEM:
114 wIndex |= pbBuffer[0];
115 request_type |= USB_DIR_OUT;
116 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8WRITE;
117// dwRequestType = (u8) RTYPE_WRITE_V8_MEMORY;
118 pipe = B2C2_USB_CTRL_PIPE_OUT;
119 break;
120 case B2C2_USB_FLASH_BLOCK:
121 request_type |= USB_DIR_OUT;
122 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8FLASH;
123// dwRequestType = (u8) RTYPE_WRITE_V8_FLASH;
124 pipe = B2C2_USB_CTRL_PIPE_OUT;
125 break;
126 default:
127 deb_info("unsupported request for v8_mem_req %x.\n",req);
128 return -EINVAL;
129 }
130 deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n",request_type,req,
131 wAddress,wIndex,buflen);
132
133 len = usb_control_msg(fc_usb->udev,pipe,
134 req,
135 request_type,
136 wAddress,
137 wIndex,
138 pbBuffer,
139 buflen,
140 nWaitTime * HZ);
141
142 debug_dump(pbBuffer,len,deb_v8);
143
144 return len == buflen ? 0 : -EIO;
145}
146
147#define bytes_left_to_read_on_page(paddr,buflen) \
148 ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \
149 ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)))
150
151static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,flexcop_usb_request_t req,
152 flexcop_usb_mem_page_t page_start, u32 addr, int extended, u8 *buf, u32 len)
153{
154 int i,ret = 0;
155 u16 wMax;
156 u32 pagechunk = 0;
157
158 switch(req) {
159 case B2C2_USB_READ_V8_MEM: wMax = USB_MEM_READ_MAX; break;
160 case B2C2_USB_WRITE_V8_MEM: wMax = USB_MEM_WRITE_MAX; break;
161 case B2C2_USB_FLASH_BLOCK: wMax = USB_FLASH_MAX; break;
162 default:
163 return -EINVAL;
164 break;
165 }
166 for (i = 0; i < len;) {
167 pagechunk = wMax < bytes_left_to_read_on_page(addr,len) ? wMax : bytes_left_to_read_on_page(addr,len);
168 deb_info("%x\n",(addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended));
169 if ((ret = flexcop_usb_v8_memory_req(fc_usb,req,
170 page_start + (addr / V8_MEMORY_PAGE_SIZE), /* actual page */
171 (addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended),
172 &buf[i],pagechunk)) < 0)
173 return ret;
174
175 addr += pagechunk;
176 len -= pagechunk;
177 }
178 return 0;
179}
180
181static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended)
182{
183 return flexcop_usb_memory_req(fc->bus_specific,B2C2_USB_READ_V8_MEM,
184 V8_MEMORY_PAGE_FLASH,0x1f010,1,fc->dvb_adapter.proposed_mac,6);
185}
186
187#if 0
188static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set,
189 flexcop_usb_utility_function_t func, u8 extra, u16 wIndex,
190 u16 buflen, u8 *pvBuffer)
191{
192 u16 wValue;
193 u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR;
194// u8 dwRequestType = (u8) RTYPE_GENERIC,
195 int nWaitTime = 2,
196 pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN,
197 len;
198
199 wValue = (func << 8) | extra;
200
201 len = usb_control_msg(fc_usb->udev,pipe,
202 B2C2_USB_UTILITY,
203 request_type,
204 wValue,
205 wIndex,
206 pvBuffer,
207 buflen,
208 nWaitTime * HZ);
209 return len == buflen ? 0 : -EIO;
210}
211#endif
212
213/* usb i2c stuff */
214static int flexcop_usb_i2c_req(struct flexcop_usb *fc_usb,
215 flexcop_usb_request_t req, flexcop_usb_i2c_function_t func,
216 flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u8 buflen)
217{
218 u16 wValue, wIndex;
219 int nWaitTime,pipe,len;
220// u8 dwRequestType;
221 u8 request_type = USB_TYPE_VENDOR;
222
223 switch (func) {
224 case USB_FUNC_I2C_WRITE:
225 case USB_FUNC_I2C_MULTIWRITE:
226 case USB_FUNC_I2C_REPEATWRITE:
227 /* DKT 020208 - add this to support special case of DiSEqC */
228 case USB_FUNC_I2C_CHECKWRITE:
229 pipe = B2C2_USB_CTRL_PIPE_OUT;
230 nWaitTime = 2;
231// dwRequestType = (u8) RTYPE_GENERIC;
232 request_type |= USB_DIR_OUT;
233 break;
234 case USB_FUNC_I2C_READ:
235 case USB_FUNC_I2C_REPEATREAD:
236 pipe = B2C2_USB_CTRL_PIPE_IN;
237 nWaitTime = 2;
238// dwRequestType = (u8) RTYPE_GENERIC;
239 request_type |= USB_DIR_IN;
240 break;
241 default:
242 deb_info("unsupported function for i2c_req %x\n",func);
243 return -EINVAL;
244 }
245 wValue = (func << 8 ) | (port << 4);
246 wIndex = (chipaddr << 8 ) | addr;
247
248 deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n",func,request_type,req,
249 ((wValue && 0xff) << 8),wValue >> 8,((wIndex && 0xff) << 8),wIndex >> 8);
250
251 len = usb_control_msg(fc_usb->udev,pipe,
252 req,
253 request_type,
254 wValue,
255 wIndex,
256 buf,
257 buflen,
258 nWaitTime * HZ);
259
260 return len == buflen ? 0 : -EREMOTEIO;
261}
262
263/* actual bus specific access functions, make sure prototype are/will be equal to pci */
264static flexcop_ibi_value flexcop_usb_read_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg)
265{
266 flexcop_ibi_value val;
267 val.raw = 0;
268 flexcop_usb_readwrite_dw(fc,reg, &val.raw, 1);
269 return val;
270}
271
272static int flexcop_usb_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg, flexcop_ibi_value val)
273{
274 return flexcop_usb_readwrite_dw(fc,reg, &val.raw, 0);
275}
276
277static int flexcop_usb_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op,
278 flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u16 len)
279{
280 if (op == FC_READ)
281 return flexcop_usb_i2c_req(fc->bus_specific,B2C2_USB_I2C_REQUEST,USB_FUNC_I2C_READ,port,chipaddr,addr,buf,len);
282 else
283 return flexcop_usb_i2c_req(fc->bus_specific,B2C2_USB_I2C_REQUEST,USB_FUNC_I2C_WRITE,port,chipaddr,addr,buf,len);
284}
285
286static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, int buffer_length)
287{
288 u8 *b;
289 int l;
290
291 deb_ts("tmp_buffer_length=%d, buffer_length=%d\n", fc_usb->tmp_buffer_length, buffer_length);
292
293 if (fc_usb->tmp_buffer_length > 0) {
294 memcpy(fc_usb->tmp_buffer+fc_usb->tmp_buffer_length, buffer, buffer_length);
295 fc_usb->tmp_buffer_length += buffer_length;
296 b = fc_usb->tmp_buffer;
297 l = fc_usb->tmp_buffer_length;
298 } else {
299 b=buffer;
300 l=buffer_length;
301 }
302
303 while (l >= 190) {
304 if (*b == 0xff)
305 switch (*(b+1) & 0x03) {
306 case 0x01: /* media packet */
307 if ( *(b+2) == 0x47 )
308 flexcop_pass_dmx_packets(fc_usb->fc_dev, b+2, 1);
309 else
310 deb_ts("not ts packet %02x %02x %02x %02x \n", *(b+2), *(b+3), *(b+4), *(b+5) );
311
312 b += 190;
313 l -= 190;
314 break;
315 default:
316 deb_ts("wrong packet type\n");
317 l = 0;
318 break;
319 }
320 else {
321 deb_ts("wrong header\n");
322 l = 0;
323 }
324 }
325
326 if (l>0)
327 memcpy(fc_usb->tmp_buffer, b, l);
328 fc_usb->tmp_buffer_length = l;
329}
330
331static void flexcop_usb_urb_complete(struct urb *urb, struct pt_regs *ptregs)
332{
333 struct flexcop_usb *fc_usb = urb->context;
334 int i;
335
336 if (urb->actual_length > 0)
337 deb_ts("urb completed, bufsize: %d actlen; %d\n",urb->transfer_buffer_length, urb->actual_length);
338
339 for (i = 0; i < urb->number_of_packets; i++) {
340 if (urb->iso_frame_desc[i].status < 0) {
341 err("iso frame descriptor %d has an error: %d\n",i,urb->iso_frame_desc[i].status);
342 } else
343 if (urb->iso_frame_desc[i].actual_length > 0) {
344 deb_ts("passed %d bytes to the demux\n",urb->iso_frame_desc[i].actual_length);
345
346 flexcop_usb_process_frame(fc_usb,
347 urb->transfer_buffer + urb->iso_frame_desc[i].offset,
348 urb->iso_frame_desc[i].actual_length);
349 }
350 urb->iso_frame_desc[i].status = 0;
351 urb->iso_frame_desc[i].actual_length = 0;
352 }
353
354 usb_submit_urb(urb,GFP_ATOMIC);
355}
356
357static int flexcop_usb_stream_control(struct flexcop_device *fc, int onoff)
358{
359 /* submit/kill iso packets */
360 return 0;
361}
362
363static void flexcop_usb_transfer_exit(struct flexcop_usb *fc_usb)
364{
365 int i;
366 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++)
367 if (fc_usb->iso_urb[i] != NULL) {
368 deb_ts("unlinking/killing urb no. %d\n",i);
369 usb_kill_urb(fc_usb->iso_urb[i]);
370 usb_free_urb(fc_usb->iso_urb[i]);
371 }
372
373 if (fc_usb->iso_buffer != NULL)
374 pci_free_consistent(NULL,fc_usb->buffer_size, fc_usb->iso_buffer, fc_usb->dma_addr);
375}
376
377static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb)
378{
379 u16 frame_size = fc_usb->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize;
380 int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * frame_size,i,j,ret;
381 int buffer_offset = 0;
382
383 deb_ts("creating %d iso-urbs with %d frames each of %d bytes size = %d.\n",
384 B2C2_USB_NUM_ISO_URB, B2C2_USB_FRAMES_PER_ISO, frame_size,bufsize);
385
386 fc_usb->iso_buffer = pci_alloc_consistent(NULL,bufsize,&fc_usb->dma_addr);
387 if (fc_usb->iso_buffer == NULL)
388 return -ENOMEM;
389 memset(fc_usb->iso_buffer, 0, bufsize);
390 fc_usb->buffer_size = bufsize;
391
392 /* creating iso urbs */
393 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++)
394 if (!(fc_usb->iso_urb[i] = usb_alloc_urb(B2C2_USB_FRAMES_PER_ISO,GFP_ATOMIC))) {
395 ret = -ENOMEM;
396 goto urb_error;
397 }
398 /* initialising and submitting iso urbs */
399 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) {
400 int frame_offset = 0;
401 struct urb *urb = fc_usb->iso_urb[i];
402 deb_ts("initializing and submitting urb no. %d (buf_offset: %d).\n",i,buffer_offset);
403
404 urb->dev = fc_usb->udev;
405 urb->context = fc_usb;
406 urb->complete = flexcop_usb_urb_complete;
407 urb->pipe = B2C2_USB_DATA_PIPE;
408 urb->transfer_flags = URB_ISO_ASAP;
409 urb->interval = 1;
410 urb->number_of_packets = B2C2_USB_FRAMES_PER_ISO;
411 urb->transfer_buffer_length = frame_size * B2C2_USB_FRAMES_PER_ISO;
412 urb->transfer_buffer = fc_usb->iso_buffer + buffer_offset;
413
414 buffer_offset += frame_size * B2C2_USB_FRAMES_PER_ISO;
415 for (j = 0; j < B2C2_USB_FRAMES_PER_ISO; j++) {
416 deb_ts("urb no: %d, frame: %d, frame_offset: %d\n",i,j,frame_offset);
417 urb->iso_frame_desc[j].offset = frame_offset;
418 urb->iso_frame_desc[j].length = frame_size;
419 frame_offset += frame_size;
420 }
421
422 if ((ret = usb_submit_urb(fc_usb->iso_urb[i],GFP_ATOMIC))) {
423 err("submitting urb %d failed with %d.",i,ret);
424 goto urb_error;
425 }
426 deb_ts("submitted urb no. %d.\n",i);
427 }
428
429/* SRAM */
430
431 flexcop_sram_set_dest(fc_usb->fc_dev,FC_SRAM_DEST_MEDIA | FC_SRAM_DEST_NET |
432 FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_WAN_USB);
433 flexcop_wan_set_speed(fc_usb->fc_dev,FC_WAN_SPEED_8MBITS);
434 flexcop_sram_ctrl(fc_usb->fc_dev,1,1,1);
435
436 ret = 0;
437 goto success;
438urb_error:
439 flexcop_usb_transfer_exit(fc_usb);
440success:
441 return ret;
442}
443
444static int flexcop_usb_init(struct flexcop_usb *fc_usb)
445{
446 /* use the alternate setting with the larges buffer */
447 usb_set_interface(fc_usb->udev,0,1);
448 switch (fc_usb->udev->speed) {
449 case USB_SPEED_LOW:
450 err("cannot handle USB speed because it is to sLOW.");
451 return -ENODEV;
452 break;
453 case USB_SPEED_FULL:
454 info("running at FULL speed.");
455 break;
456 case USB_SPEED_HIGH:
457 info("running at HIGH speed.");
458 break;
459 case USB_SPEED_UNKNOWN: /* fall through */
460 default:
461 err("cannot handle USB speed because it is unkown.");
462 return -ENODEV;
463 }
464 usb_set_intfdata(fc_usb->uintf, fc_usb);
465 return 0;
466}
467
468static void flexcop_usb_exit(struct flexcop_usb *fc_usb)
469{
470 usb_set_intfdata(fc_usb->uintf, NULL);
471}
472
473static int flexcop_usb_probe(struct usb_interface *intf,
474 const struct usb_device_id *id)
475{
476 struct usb_device *udev = interface_to_usbdev(intf);
477 struct flexcop_usb *fc_usb = NULL;
478 struct flexcop_device *fc = NULL;
479 int ret;
480
481 if ((fc = flexcop_device_kmalloc(sizeof(struct flexcop_usb))) == NULL) {
482 err("out of memory\n");
483 return -ENOMEM;
484 }
485
486/* general flexcop init */
487 fc_usb = fc->bus_specific;
488 fc_usb->fc_dev = fc;
489
490 fc->read_ibi_reg = flexcop_usb_read_ibi_reg;
491 fc->write_ibi_reg = flexcop_usb_write_ibi_reg;
492 fc->i2c_request = flexcop_usb_i2c_request;
493 fc->get_mac_addr = flexcop_usb_get_mac_addr;
494
495 fc->stream_control = flexcop_usb_stream_control;
496
497 fc->pid_filtering = 1;
498 fc->bus_type = FC_USB;
499
500 fc->dev = &udev->dev;
501 fc->owner = THIS_MODULE;
502
503/* bus specific part */
504 fc_usb->udev = udev;
505 fc_usb->uintf = intf;
506 if ((ret = flexcop_usb_init(fc_usb)) != 0)
507 goto err_kfree;
508
509/* init flexcop */
510 if ((ret = flexcop_device_initialize(fc)) != 0)
511 goto err_usb_exit;
512
513/* xfer init */
514 if ((ret = flexcop_usb_transfer_init(fc_usb)) != 0)
515 goto err_fc_exit;
516
517 info("%s successfully initialized and connected.",DRIVER_NAME);
518 ret = 0;
519 goto success;
520err_fc_exit:
521 flexcop_device_exit(fc);
522err_usb_exit:
523 flexcop_usb_exit(fc_usb);
524err_kfree:
525 flexcop_device_kfree(fc);
526success:
527 return ret;
528}
529
530static void flexcop_usb_disconnect(struct usb_interface *intf)
531{
532 struct flexcop_usb *fc_usb = usb_get_intfdata(intf);
533 flexcop_usb_transfer_exit(fc_usb);
534 flexcop_device_exit(fc_usb->fc_dev);
535 flexcop_usb_exit(fc_usb);
536 flexcop_device_kfree(fc_usb->fc_dev);
537 info("%s successfully deinitialized and disconnected.",DRIVER_NAME);
538}
539
540static struct usb_device_id flexcop_usb_table [] = {
541 { USB_DEVICE(0x0af7, 0x0101) },
542 { }
543};
544
545/* usb specific object needed to register this driver with the usb subsystem */
546static struct usb_driver flexcop_usb_driver = {
547 .owner = THIS_MODULE,
548 .name = "Technisat/B2C2 FlexCop II/IIb/III USB",
549 .probe = flexcop_usb_probe,
550 .disconnect = flexcop_usb_disconnect,
551 .id_table = flexcop_usb_table,
552};
553
554/* module stuff */
555static int __init flexcop_usb_module_init(void)
556{
557 int result;
558 if ((result = usb_register(&flexcop_usb_driver))) {
559 err("usb_register failed. (%d)",result);
560 return result;
561 }
562
563 return 0;
564}
565
566static void __exit flexcop_usb_module_exit(void)
567{
568 /* deregister this driver from the USB subsystem */
569 usb_deregister(&flexcop_usb_driver);
570}
571
572module_init(flexcop_usb_module_init);
573module_exit(flexcop_usb_module_exit);
574
575MODULE_AUTHOR(DRIVER_AUTHOR);
576MODULE_DESCRIPTION(DRIVER_NAME);
577MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.h b/drivers/media/dvb/b2c2/flexcop-usb.h
new file mode 100644
index 000000000000..630e647a2caa
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop-usb.h
@@ -0,0 +1,119 @@
1#ifndef __FLEXCOP_USB_H_INCLUDED__
2#define __FLEXCOP_USB_H_INCLUDED__
3
4#include <linux/usb.h>
5
6/* transfer parameters */
7#define B2C2_USB_FRAMES_PER_ISO 4
8#define B2C2_USB_NUM_ISO_URB 4
9
10#define B2C2_USB_CTRL_PIPE_IN usb_rcvctrlpipe(fc_usb->udev,0)
11#define B2C2_USB_CTRL_PIPE_OUT usb_sndctrlpipe(fc_usb->udev,0)
12#define B2C2_USB_DATA_PIPE usb_rcvisocpipe(fc_usb->udev,0x81)
13
14struct flexcop_usb {
15 struct usb_device *udev;
16 struct usb_interface *uintf;
17
18 u8 *iso_buffer;
19 int buffer_size;
20 dma_addr_t dma_addr;
21 struct urb *iso_urb[B2C2_USB_NUM_ISO_URB];
22
23 struct flexcop_device *fc_dev;
24
25 u8 tmp_buffer[1023+190];
26 int tmp_buffer_length;
27};
28
29#if 0
30/* request types TODO What is its use?*/
31typedef enum {
32
33/* something is wrong with this part
34 RTYPE_READ_DW = (1 << 6),
35 RTYPE_WRITE_DW_1 = (3 << 6),
36 RTYPE_READ_V8_MEMORY = (6 << 6),
37 RTYPE_WRITE_V8_MEMORY = (7 << 6),
38 RTYPE_WRITE_V8_FLASH = (8 << 6),
39 RTYPE_GENERIC = (9 << 6),
40*/
41} flexcop_usb_request_type_t;
42#endif
43
44/* request */
45typedef enum {
46 B2C2_USB_WRITE_V8_MEM = 0x04,
47 B2C2_USB_READ_V8_MEM = 0x05,
48 B2C2_USB_READ_REG = 0x08,
49 B2C2_USB_WRITE_REG = 0x0A,
50/* B2C2_USB_WRITEREGLO = 0x0A, */
51 B2C2_USB_WRITEREGHI = 0x0B,
52 B2C2_USB_FLASH_BLOCK = 0x10,
53 B2C2_USB_I2C_REQUEST = 0x11,
54 B2C2_USB_UTILITY = 0x12,
55} flexcop_usb_request_t;
56
57/* function definition for I2C_REQUEST */
58typedef enum {
59 USB_FUNC_I2C_WRITE = 0x01,
60 USB_FUNC_I2C_MULTIWRITE = 0x02,
61 USB_FUNC_I2C_READ = 0x03,
62 USB_FUNC_I2C_REPEATWRITE = 0x04,
63 USB_FUNC_GET_DESCRIPTOR = 0x05,
64 USB_FUNC_I2C_REPEATREAD = 0x06,
65/* DKT 020208 - add this to support special case of DiSEqC */
66 USB_FUNC_I2C_CHECKWRITE = 0x07,
67 USB_FUNC_I2C_CHECKRESULT = 0x08,
68} flexcop_usb_i2c_function_t;
69
70/*
71 * function definition for UTILITY request 0x12
72 * DKT 020304 - new utility function
73 */
74typedef enum {
75 UTILITY_SET_FILTER = 0x01,
76 UTILITY_DATA_ENABLE = 0x02,
77 UTILITY_FLEX_MULTIWRITE = 0x03,
78 UTILITY_SET_BUFFER_SIZE = 0x04,
79 UTILITY_FLEX_OPERATOR = 0x05,
80 UTILITY_FLEX_RESET300_START = 0x06,
81 UTILITY_FLEX_RESET300_STOP = 0x07,
82 UTILITY_FLEX_RESET300 = 0x08,
83 UTILITY_SET_ISO_SIZE = 0x09,
84 UTILITY_DATA_RESET = 0x0A,
85 UTILITY_GET_DATA_STATUS = 0x10,
86 UTILITY_GET_V8_REG = 0x11,
87/* DKT 020326 - add function for v1.14 */
88 UTILITY_SRAM_WRITE = 0x12,
89 UTILITY_SRAM_READ = 0x13,
90 UTILITY_SRAM_TESTFILL = 0x14,
91 UTILITY_SRAM_TESTSET = 0x15,
92 UTILITY_SRAM_TESTVERIFY = 0x16,
93} flexcop_usb_utility_function_t;
94
95#define B2C2_WAIT_FOR_OPERATION_RW 1*HZ /* 1 s */
96#define B2C2_WAIT_FOR_OPERATION_RDW 3*HZ /* 3 s */
97#define B2C2_WAIT_FOR_OPERATION_WDW 1*HZ /* 1 s */
98
99#define B2C2_WAIT_FOR_OPERATION_V8READ 3*HZ /* 3 s */
100#define B2C2_WAIT_FOR_OPERATION_V8WRITE 3*HZ /* 3 s */
101#define B2C2_WAIT_FOR_OPERATION_V8FLASH 3*HZ /* 3 s */
102
103typedef enum {
104 V8_MEMORY_PAGE_DVB_CI = 0x20,
105 V8_MEMORY_PAGE_DVB_DS = 0x40,
106 V8_MEMORY_PAGE_MULTI2 = 0x60,
107 V8_MEMORY_PAGE_FLASH = 0x80
108} flexcop_usb_mem_page_t;
109
110#define V8_MEMORY_EXTENDED (1 << 15)
111
112#define USB_MEM_READ_MAX 32
113#define USB_MEM_WRITE_MAX 1
114#define USB_FLASH_MAX 8
115
116#define V8_MEMORY_PAGE_SIZE 0x8000 // 32K
117#define V8_MEMORY_PAGE_MASK 0x7FFF
118
119#endif
diff --git a/drivers/media/dvb/b2c2/flexcop.c b/drivers/media/dvb/b2c2/flexcop.c
new file mode 100644
index 000000000000..8b5d14dd36e3
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop.c
@@ -0,0 +1,286 @@
1/*
2 * flexcop.c - driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher <patrick.boettcher@desy.de>
5 *
6 * based on the skystar2-driver
7 * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
8 *
9 * Acknowledgements:
10 * John Jurrius from BBTI, Inc. for extensive support with
11 * code examples and data books
12 *
13 * Bjarne Steinsbo, bjarne at steinsbo.com (some ideas for rewriting)
14 *
15 * Contributions to the skystar2-driver have been done by
16 * Vincenzo Di Massa, hawk.it at tiscalinet.it (several DiSEqC fixes)
17 * Roberto Ragusa, r.ragusa at libero.it (polishing, restyling the code)
18 * Niklas Peinecke, peinecke at gdv.uni-hannover.de (hardware pid/mac filtering)
19 *
20 *
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public License
23 * as published by the Free Software Foundation; either version 2.1
24 * of the License, or (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 */
35
36#include "flexcop.h"
37
38#define DRIVER_NAME "B2C2 FlexcopII/II(b)/III digital TV receiver chip"
39#define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de"
40
41#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
42#define DEBSTATUS ""
43#else
44#define DEBSTATUS " (debugging is not enabled)"
45#endif
46
47int b2c2_flexcop_debug;
48module_param_named(debug, b2c2_flexcop_debug, int, 0644);
49MODULE_PARM_DESC(debug, "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram (|-able))." DEBSTATUS);
50#undef DEBSTATUS
51
52/* global zero for ibi values */
53flexcop_ibi_value ibi_zero;
54
55static int flexcop_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
56{
57 struct flexcop_device *fc = dvbdmxfeed->demux->priv;
58 return flexcop_pid_feed_control(fc,dvbdmxfeed,1);
59}
60
61static int flexcop_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
62{
63 struct flexcop_device *fc = dvbdmxfeed->demux->priv;
64 return flexcop_pid_feed_control(fc,dvbdmxfeed,0);
65}
66
67static int flexcop_dvb_init(struct flexcop_device *fc)
68{
69 int ret;
70 if ((ret = dvb_register_adapter(&fc->dvb_adapter,"FlexCop Digital TV device",fc->owner)) < 0) {
71 err("error registering DVB adapter");
72 return ret;
73 }
74 fc->dvb_adapter.priv = fc;
75
76 fc->demux.dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
77 fc->demux.priv = fc;
78
79 fc->demux.filternum = fc->demux.feednum = FC_MAX_FEED;
80
81 fc->demux.start_feed = flexcop_dvb_start_feed;
82 fc->demux.stop_feed = flexcop_dvb_stop_feed;
83 fc->demux.write_to_decoder = NULL;
84
85 if ((ret = dvb_dmx_init(&fc->demux)) < 0) {
86 err("dvb_dmx failed: error %d",ret);
87 goto err_dmx;
88 }
89
90 fc->hw_frontend.source = DMX_FRONTEND_0;
91
92 fc->dmxdev.filternum = fc->demux.feednum;
93 fc->dmxdev.demux = &fc->demux.dmx;
94 fc->dmxdev.capabilities = 0;
95 if ((ret = dvb_dmxdev_init(&fc->dmxdev, &fc->dvb_adapter)) < 0) {
96 err("dvb_dmxdev_init failed: error %d",ret);
97 goto err_dmx_dev;
98 }
99
100 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
101 err("adding hw_frontend to dmx failed: error %d",ret);
102 goto err_dmx_add_hw_frontend;
103 }
104
105 fc->mem_frontend.source = DMX_MEMORY_FE;
106 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->mem_frontend)) < 0) {
107 err("adding mem_frontend to dmx failed: error %d",ret);
108 goto err_dmx_add_mem_frontend;
109 }
110
111 if ((ret = fc->demux.dmx.connect_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
112 err("connect frontend failed: error %d",ret);
113 goto err_connect_frontend;
114 }
115
116 dvb_net_init(&fc->dvb_adapter, &fc->dvbnet, &fc->demux.dmx);
117
118 fc->init_state |= FC_STATE_DVB_INIT;
119 goto success;
120
121err_connect_frontend:
122 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->mem_frontend);
123err_dmx_add_mem_frontend:
124 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->hw_frontend);
125err_dmx_add_hw_frontend:
126 dvb_dmxdev_release(&fc->dmxdev);
127err_dmx_dev:
128 dvb_dmx_release(&fc->demux);
129err_dmx:
130 dvb_unregister_adapter(&fc->dvb_adapter);
131 return ret;
132
133success:
134 return 0;
135}
136
137static void flexcop_dvb_exit(struct flexcop_device *fc)
138{
139 if (fc->init_state & FC_STATE_DVB_INIT) {
140 dvb_net_release(&fc->dvbnet);
141
142 fc->demux.dmx.close(&fc->demux.dmx);
143 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->mem_frontend);
144 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->hw_frontend);
145 dvb_dmxdev_release(&fc->dmxdev);
146 dvb_dmx_release(&fc->demux);
147 dvb_unregister_adapter(&fc->dvb_adapter);
148
149 deb_info("deinitialized dvb stuff\n");
150 }
151 fc->init_state &= ~FC_STATE_DVB_INIT;
152}
153
154/* these methods are necessary to achieve the long-term-goal of hiding the
155 * struct flexcop_device from the bus-parts */
156void flexcop_pass_dmx_data(struct flexcop_device *fc, u8 *buf, u32 len)
157{
158 dvb_dmx_swfilter(&fc->demux, buf, len);
159}
160EXPORT_SYMBOL(flexcop_pass_dmx_data);
161
162void flexcop_pass_dmx_packets(struct flexcop_device *fc, u8 *buf, u32 no)
163{
164 dvb_dmx_swfilter_packets(&fc->demux, buf, no);
165}
166EXPORT_SYMBOL(flexcop_pass_dmx_packets);
167
168static void flexcop_reset(struct flexcop_device *fc)
169{
170 flexcop_ibi_value v210,v204;
171
172/* reset the flexcop itself */
173 fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
174
175 v210.raw = 0;
176 v210.sw_reset_210.reset_blocks = 0xff;
177 v210.sw_reset_210.Block_reset_enable = 0xb2;
178 fc->write_ibi_reg(fc,sw_reset_210,v210);
179
180/* reset the periphical devices */
181
182 v204 = fc->read_ibi_reg(fc,misc_204);
183 v204.misc_204.Per_reset_sig = 0;
184 fc->write_ibi_reg(fc,misc_204,v204);
185 v204.misc_204.Per_reset_sig = 1;
186 fc->write_ibi_reg(fc,misc_204,v204);
187}
188
189struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
190{
191 void *bus;
192 struct flexcop_device *fc = kmalloc(sizeof(struct flexcop_device), GFP_KERNEL);
193 if (!fc) {
194 err("no memory");
195 return NULL;
196 }
197 memset(fc, 0, sizeof(struct flexcop_device));
198
199 bus = kmalloc(bus_specific_len, GFP_KERNEL);
200 if (!bus) {
201 err("no memory");
202 kfree(fc);
203 return NULL;
204 }
205 memset(bus, 0, bus_specific_len);
206
207 fc->bus_specific = bus;
208
209 return fc;
210}
211EXPORT_SYMBOL(flexcop_device_kmalloc);
212
213void flexcop_device_kfree(struct flexcop_device *fc)
214{
215 kfree(fc->bus_specific);
216 kfree(fc);
217}
218EXPORT_SYMBOL(flexcop_device_kfree);
219
220int flexcop_device_initialize(struct flexcop_device *fc)
221{
222 int ret;
223 ibi_zero.raw = 0;
224
225 flexcop_reset(fc);
226 flexcop_determine_revision(fc);
227 flexcop_sram_init(fc);
228 flexcop_hw_filter_init(fc);
229
230 flexcop_smc_ctrl(fc, 0);
231
232 if ((ret = flexcop_dvb_init(fc)))
233 goto error;
234
235 /* do the MAC address reading after initializing the dvb_adapter */
236 if (fc->get_mac_addr(fc, 0) == 0) {
237 u8 *b = fc->dvb_adapter.proposed_mac;
238 info("MAC address = %02x:%02x:%02x:%02x:%02x:%02x", b[0],b[1],b[2],b[3],b[4],b[5]);
239 flexcop_set_mac_filter(fc,b);
240 flexcop_mac_filter_ctrl(fc,1);
241 } else
242 warn("reading of MAC address failed.\n");
243
244
245 if ((ret = flexcop_i2c_init(fc)))
246 goto error;
247
248 if ((ret = flexcop_frontend_init(fc)))
249 goto error;
250
251 flexcop_device_name(fc,"initialization of","complete");
252
253 ret = 0;
254 goto success;
255error:
256 flexcop_device_exit(fc);
257success:
258 return ret;
259}
260EXPORT_SYMBOL(flexcop_device_initialize);
261
262void flexcop_device_exit(struct flexcop_device *fc)
263{
264 flexcop_frontend_exit(fc);
265 flexcop_i2c_exit(fc);
266 flexcop_dvb_exit(fc);
267}
268EXPORT_SYMBOL(flexcop_device_exit);
269
270static int flexcop_module_init(void)
271{
272 info(DRIVER_NAME " loaded successfully");
273 return 0;
274}
275
276static void flexcop_module_cleanup(void)
277{
278 info(DRIVER_NAME " unloaded successfully");
279}
280
281module_init(flexcop_module_init);
282module_exit(flexcop_module_cleanup);
283
284MODULE_AUTHOR(DRIVER_AUTHOR);
285MODULE_DESCRIPTION(DRIVER_NAME);
286MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/b2c2/flexcop.h b/drivers/media/dvb/b2c2/flexcop.h
new file mode 100644
index 000000000000..caa343a97bdc
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop.h
@@ -0,0 +1,30 @@
1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop.h - private header file for all flexcop-chip-source files.
5 *
6 * see flexcop.c for copyright information.
7 */
8#ifndef __FLEXCOP_H__
9#define __FLEXCOP_H___
10
11#define FC_LOG_PREFIX "b2c2-flexcop"
12#include "flexcop-common.h"
13
14extern int b2c2_flexcop_debug;
15
16/* debug */
17#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
18#define dprintk(level,args...) \
19 do { if ((b2c2_flexcop_debug & level)) printk(args); } while (0)
20#else
21#define dprintk(level,args...)
22#endif
23
24#define deb_info(args...) dprintk(0x01,args)
25#define deb_tuner(args...) dprintk(0x02,args)
26#define deb_i2c(args...) dprintk(0x04,args)
27#define deb_ts(args...) dprintk(0x08,args)
28#define deb_sram(args...) dprintk(0x10,args)
29
30#endif
diff --git a/drivers/media/dvb/b2c2/skystar2.c b/drivers/media/dvb/b2c2/skystar2.c
index 336c178fcd5f..acbc4c34f72a 100644
--- a/drivers/media/dvb/b2c2/skystar2.c
+++ b/drivers/media/dvb/b2c2/skystar2.c
@@ -97,7 +97,7 @@ struct adapter {
97 u8 mac_addr[8]; 97 u8 mac_addr[8];
98 u32 dw_sram_type; 98 u32 dw_sram_type;
99 99
100 struct dvb_adapter *dvb_adapter; 100 struct dvb_adapter dvb_adapter;
101 struct dvb_demux demux; 101 struct dvb_demux demux;
102 struct dmxdev dmxdev; 102 struct dmxdev dmxdev;
103 struct dmx_frontend hw_frontend; 103 struct dmx_frontend hw_frontend;
@@ -2461,7 +2461,7 @@ static void frontend_init(struct adapter *skystar2)
2461 skystar2->pdev->subsystem_vendor, 2461 skystar2->pdev->subsystem_vendor,
2462 skystar2->pdev->subsystem_device); 2462 skystar2->pdev->subsystem_device);
2463 } else { 2463 } else {
2464 if (dvb_register_frontend(skystar2->dvb_adapter, skystar2->fe)) { 2464 if (dvb_register_frontend(&skystar2->dvb_adapter, skystar2->fe)) {
2465 printk("skystar2: Frontend registration failed!\n"); 2465 printk("skystar2: Frontend registration failed!\n");
2466 if (skystar2->fe->ops->release) 2466 if (skystar2->fe->ops->release)
2467 skystar2->fe->ops->release(skystar2->fe); 2467 skystar2->fe->ops->release(skystar2->fe);
@@ -2486,17 +2486,17 @@ static int skystar2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2486 if (ret < 0) 2486 if (ret < 0)
2487 goto out; 2487 goto out;
2488 2488
2489 ret = dvb_register_adapter(&dvb_adapter, skystar2_pci_driver.name, 2489 adapter = pci_get_drvdata(pdev);
2490 dvb_adapter = &adapter->dvb_adapter;
2491
2492 ret = dvb_register_adapter(dvb_adapter, skystar2_pci_driver.name,
2490 THIS_MODULE); 2493 THIS_MODULE);
2491 if (ret < 0) { 2494 if (ret < 0) {
2492 printk("%s: Error registering DVB adapter\n", __FUNCTION__); 2495 printk("%s: Error registering DVB adapter\n", __FUNCTION__);
2493 goto err_halt; 2496 goto err_halt;
2494 } 2497 }
2495 2498
2496 adapter = pci_get_drvdata(pdev);
2497
2498 dvb_adapter->priv = adapter; 2499 dvb_adapter->priv = adapter;
2499 adapter->dvb_adapter = dvb_adapter;
2500 2500
2501 2501
2502 init_MUTEX(&adapter->i2c_sem); 2502 init_MUTEX(&adapter->i2c_sem);
@@ -2541,7 +2541,7 @@ static int skystar2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2541 adapter->dmxdev.demux = dmx; 2541 adapter->dmxdev.demux = dmx;
2542 adapter->dmxdev.capabilities = 0; 2542 adapter->dmxdev.capabilities = 0;
2543 2543
2544 ret = dvb_dmxdev_init(&adapter->dmxdev, adapter->dvb_adapter); 2544 ret = dvb_dmxdev_init(&adapter->dmxdev, &adapter->dvb_adapter);
2545 if (ret < 0) 2545 if (ret < 0)
2546 goto err_dmx_release; 2546 goto err_dmx_release;
2547 2547
@@ -2559,7 +2559,7 @@ static int skystar2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2559 if (ret < 0) 2559 if (ret < 0)
2560 goto err_remove_mem_frontend; 2560 goto err_remove_mem_frontend;
2561 2561
2562 dvb_net_init(adapter->dvb_adapter, &adapter->dvbnet, &dvbdemux->dmx); 2562 dvb_net_init(&adapter->dvb_adapter, &adapter->dvbnet, &dvbdemux->dmx);
2563 2563
2564 frontend_init(adapter); 2564 frontend_init(adapter);
2565out: 2565out:
@@ -2576,7 +2576,7 @@ err_dmx_release:
2576err_i2c_del: 2576err_i2c_del:
2577 i2c_del_adapter(&adapter->i2c_adap); 2577 i2c_del_adapter(&adapter->i2c_adap);
2578err_dvb_unregister: 2578err_dvb_unregister:
2579 dvb_unregister_adapter(adapter->dvb_adapter); 2579 dvb_unregister_adapter(&adapter->dvb_adapter);
2580err_halt: 2580err_halt:
2581 driver_halt(pdev); 2581 driver_halt(pdev);
2582 goto out; 2582 goto out;
@@ -2605,7 +2605,7 @@ static void skystar2_remove(struct pci_dev *pdev)
2605 if (adapter->fe != NULL) 2605 if (adapter->fe != NULL)
2606 dvb_unregister_frontend(adapter->fe); 2606 dvb_unregister_frontend(adapter->fe);
2607 2607
2608 dvb_unregister_adapter(adapter->dvb_adapter); 2608 dvb_unregister_adapter(&adapter->dvb_adapter);
2609 2609
2610 i2c_del_adapter(&adapter->i2c_adap); 2610 i2c_del_adapter(&adapter->i2c_adap);
2611 2611
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index e7d11e0667a8..b12545f093f8 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -11,9 +11,8 @@ config DVB_BT8XX
11 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards and 11 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards and
12 pcHDTV HD2000 cards. 12 pcHDTV HD2000 cards.
13 13
14 Since these cards have no MPEG decoder onboard, they transmit 14 Since these cards have no MPEG decoder onboard, they transmit
15 only compressed MPEG data over the PCI bus, so you need 15 only compressed MPEG data over the PCI bus, so you need
16 an external software decoder to watch TV on your computer. 16 an external software decoder to watch TV on your computer.
17 17
18 Say Y if you own such a device and want to use it. 18 Say Y if you own such a device and want to use it.
19
diff --git a/drivers/media/dvb/bt8xx/Makefile b/drivers/media/dvb/bt8xx/Makefile
index 9da8604b9e18..d188e4c670b5 100644
--- a/drivers/media/dvb/bt8xx/Makefile
+++ b/drivers/media/dvb/bt8xx/Makefile
@@ -1,5 +1,3 @@
1 1obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o
2obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o
3 2
4EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/video -Idrivers/media/dvb/frontends 3EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/video -Idrivers/media/dvb/frontends
5
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index 213ff7902024..3c5a8e273c4a 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -4,27 +4,27 @@
4 * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> 4 * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de>
5 * 5 *
6 * large parts based on the bttv driver 6 * large parts based on the bttv driver
7 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de) 7 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@metzlerbros.de)
8 * & Marcus Metzler (mocm@thp.uni-koeln.de) 8 * & Marcus Metzler (mocm@metzlerbros.de)
9 * (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de> 9 * (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
10 * 10 *
11 * This program is free software; you can redistribute it and/or 11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License 12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2 13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version. 14 * of the License, or (at your option) any later version.
15 * 15 *
16 16
17 * This program is distributed in the hope that it will be useful, 17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details. 20 * GNU General Public License for more details.
21 * 21 *
22 22
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27 * 27 *
28 */ 28 */
29 29
30#include <linux/module.h> 30#include <linux/module.h>
@@ -58,7 +58,7 @@ module_param_named(verbose, bt878_verbose, int, 0444);
58MODULE_PARM_DESC(verbose, 58MODULE_PARM_DESC(verbose,
59 "verbose startup messages, default is 1 (yes)"); 59 "verbose startup messages, default is 1 (yes)");
60module_param_named(debug, bt878_debug, int, 0644); 60module_param_named(debug, bt878_debug, int, 0644);
61MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); 61MODULE_PARM_DESC(debug, "Turn on/off debugging, default is 0 (off).");
62 62
63int bt878_num; 63int bt878_num;
64struct bt878 bt878[BT878_MAX]; 64struct bt878 bt878[BT878_MAX];
@@ -128,21 +128,21 @@ static int bt878_mem_alloc(struct bt878 *bt)
128} 128}
129 129
130/* RISC instructions */ 130/* RISC instructions */
131#define RISC_WRITE (0x01 << 28) 131#define RISC_WRITE (0x01 << 28)
132#define RISC_JUMP (0x07 << 28) 132#define RISC_JUMP (0x07 << 28)
133#define RISC_SYNC (0x08 << 28) 133#define RISC_SYNC (0x08 << 28)
134 134
135/* RISC bits */ 135/* RISC bits */
136#define RISC_WR_SOL (1 << 27) 136#define RISC_WR_SOL (1 << 27)
137#define RISC_WR_EOL (1 << 26) 137#define RISC_WR_EOL (1 << 26)
138#define RISC_IRQ (1 << 24) 138#define RISC_IRQ (1 << 24)
139#define RISC_STATUS(status) ((((~status) & 0x0F) << 20) | ((status & 0x0F) << 16)) 139#define RISC_STATUS(status) ((((~status) & 0x0F) << 20) | ((status & 0x0F) << 16))
140#define RISC_SYNC_RESYNC (1 << 15) 140#define RISC_SYNC_RESYNC (1 << 15)
141#define RISC_SYNC_FM1 0x06 141#define RISC_SYNC_FM1 0x06
142#define RISC_SYNC_VRO 0x0C 142#define RISC_SYNC_VRO 0x0C
143 143
144#define RISC_FLUSH() bt->risc_pos = 0 144#define RISC_FLUSH() bt->risc_pos = 0
145#define RISC_INSTR(instr) bt->risc_cpu[bt->risc_pos++] = cpu_to_le32(instr) 145#define RISC_INSTR(instr) bt->risc_cpu[bt->risc_pos++] = cpu_to_le32(instr)
146 146
147static int bt878_make_risc(struct bt878 *bt) 147static int bt878_make_risc(struct bt878 *bt)
148{ 148{
@@ -173,7 +173,7 @@ static void bt878_risc_program(struct bt878 *bt, u32 op_sync_orin)
173 RISC_INSTR(RISC_SYNC | RISC_SYNC_FM1 | op_sync_orin); 173 RISC_INSTR(RISC_SYNC | RISC_SYNC_FM1 | op_sync_orin);
174 RISC_INSTR(0); 174 RISC_INSTR(0);
175 175
176 dprintk("bt878: risc len lines %u, bytes per line %u\n", 176 dprintk("bt878: risc len lines %u, bytes per line %u\n",
177 bt->line_count, bt->line_bytes); 177 bt->line_count, bt->line_bytes);
178 for (line = 0; line < bt->line_count; line++) { 178 for (line = 0; line < bt->line_count; line++) {
179 // At the beginning of every block we issue an IRQ with previous (finished) block number set 179 // At the beginning of every block we issue an IRQ with previous (finished) block number set
@@ -228,14 +228,14 @@ void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin,
228 * Hacked for DST to: 228 * Hacked for DST to:
229 * SCERR | OCERR | FDSR | FTRGT | FBUS | RISCI 229 * SCERR | OCERR | FDSR | FTRGT | FBUS | RISCI
230 */ 230 */
231 int_mask = BT878_ASCERR | BT878_AOCERR | BT878_APABORT | 231 int_mask = BT878_ASCERR | BT878_AOCERR | BT878_APABORT |
232 BT878_ARIPERR | BT878_APPERR | BT878_AFDSR | BT878_AFTRGT | 232 BT878_ARIPERR | BT878_APPERR | BT878_AFDSR | BT878_AFTRGT |
233 BT878_AFBUS | BT878_ARISCI; 233 BT878_AFBUS | BT878_ARISCI;
234 234
235 235
236 /* ignore pesky bits */ 236 /* ignore pesky bits */
237 int_mask &= ~irq_err_ignore; 237 int_mask &= ~irq_err_ignore;
238 238
239 btwrite(int_mask, BT878_AINT_MASK); 239 btwrite(int_mask, BT878_AINT_MASK);
240 btwrite(controlreg, BT878_AGPIO_DMA_CTL); 240 btwrite(controlreg, BT878_AGPIO_DMA_CTL);
241} 241}
@@ -461,9 +461,9 @@ static int __devinit bt878_probe(struct pci_dev *dev,
461 pci_set_drvdata(dev, bt); 461 pci_set_drvdata(dev, bt);
462 462
463/* if(init_bt878(btv) < 0) { 463/* if(init_bt878(btv) < 0) {
464 bt878_remove(dev); 464 bt878_remove(dev);
465 return -EIO; 465 return -EIO;
466 } 466 }
467*/ 467*/
468 468
469 if ((result = bt878_mem_alloc(bt))) { 469 if ((result = bt878_mem_alloc(bt))) {
@@ -536,10 +536,10 @@ static struct pci_device_id bt878_pci_tbl[] __devinitdata = {
536MODULE_DEVICE_TABLE(pci, bt878_pci_tbl); 536MODULE_DEVICE_TABLE(pci, bt878_pci_tbl);
537 537
538static struct pci_driver bt878_pci_driver = { 538static struct pci_driver bt878_pci_driver = {
539 .name = "bt878", 539 .name = "bt878",
540 .id_table = bt878_pci_tbl, 540 .id_table = bt878_pci_tbl,
541 .probe = bt878_probe, 541 .probe = bt878_probe,
542 .remove = bt878_remove, 542 .remove = bt878_remove,
543}; 543};
544 544
545static int bt878_pci_driver_registered = 0; 545static int bt878_pci_driver_registered = 0;
@@ -558,7 +558,7 @@ static int bt878_init_module(void)
558 (BT878_VERSION_CODE >> 8) & 0xff, 558 (BT878_VERSION_CODE >> 8) & 0xff,
559 BT878_VERSION_CODE & 0xff); 559 BT878_VERSION_CODE & 0xff);
560/* 560/*
561 bt878_check_chipset(); 561 bt878_check_chipset();
562*/ 562*/
563 /* later we register inside of bt878_find_audio_dma() 563 /* later we register inside of bt878_find_audio_dma()
564 * because we may want to ignore certain cards */ 564 * because we may want to ignore certain cards */
diff --git a/drivers/media/dvb/bt8xx/bt878.h b/drivers/media/dvb/bt8xx/bt878.h
index e1b9809d1b08..837623f7fcdf 100644
--- a/drivers/media/dvb/bt8xx/bt878.h
+++ b/drivers/media/dvb/bt8xx/bt878.h
@@ -1,4 +1,4 @@
1/* 1/*
2 bt878.h - Bt878 audio module (register offsets) 2 bt878.h - Bt878 audio module (register offsets)
3 3
4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de> 4 Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@t-online.de>
@@ -120,14 +120,14 @@ struct bt878 {
120 u32 risc_pos; 120 u32 risc_pos;
121 121
122 struct tasklet_struct tasklet; 122 struct tasklet_struct tasklet;
123 int shutdown; 123 int shutdown;
124}; 124};
125 125
126extern struct bt878 bt878[BT878_MAX]; 126extern struct bt878 bt878[BT878_MAX];
127 127
128void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin, 128void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin,
129 u32 irq_err_ignore); 129 u32 irq_err_ignore);
130void bt878_stop(struct bt878 *bt); 130void bt878_stop(struct bt878 *bt);
131 131
132#if defined(__powerpc__) /* big-endian */ 132#if defined(__powerpc__) /* big-endian */
133extern __inline__ void io_st_le32(volatile unsigned __iomem *addr, unsigned val) 133extern __inline__ void io_st_le32(volatile unsigned __iomem *addr, unsigned val)
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index eac83768dfd0..1339912c308b 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1,25 +1,25 @@
1/* 1/*
2 Frontend-driver for TwinHan DST Frontend
3 2
4 Copyright (C) 2003 Jamie Honan 3 Frontend/Card driver for TwinHan DST Frontend
4 Copyright (C) 2003 Jamie Honan
5 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
5 6
6 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 10 (at your option) any later version.
10 11
11 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 15 GNU General Public License for more details.
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/ 20*/
22 21
22
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
@@ -31,59 +31,22 @@
31 31
32#include "dvb_frontend.h" 32#include "dvb_frontend.h"
33#include "dst_priv.h" 33#include "dst_priv.h"
34#include "dst.h" 34#include "dst_common.h"
35 35
36struct dst_state {
37
38 struct i2c_adapter* i2c;
39
40 struct bt878* bt;
41
42 struct dvb_frontend_ops ops;
43
44 /* configuration settings */
45 const struct dst_config* config;
46
47 struct dvb_frontend frontend;
48
49 /* private demodulator data */
50 u8 tx_tuna[10];
51 u8 rx_tuna[10];
52 u8 rxbuffer[10];
53 u8 diseq_flags;
54 u8 dst_type;
55 u32 type_flags;
56 u32 frequency; /* intermediate frequency in kHz for QPSK */
57 fe_spectral_inversion_t inversion;
58 u32 symbol_rate; /* symbol rate in Symbols per second */
59 fe_code_rate_t fec;
60 fe_sec_voltage_t voltage;
61 fe_sec_tone_mode_t tone;
62 u32 decode_freq;
63 u8 decode_lock;
64 u16 decode_strength;
65 u16 decode_snr;
66 unsigned long cur_jiff;
67 u8 k22;
68 fe_bandwidth_t bandwidth;
69};
70 36
71static unsigned int dst_verbose = 0; 37static unsigned int verbose = 1;
72module_param(dst_verbose, int, 0644); 38module_param(verbose, int, 0644);
73MODULE_PARM_DESC(dst_verbose, "verbose startup messages, default is 1 (yes)"); 39MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
74static unsigned int dst_debug = 0;
75module_param(dst_debug, int, 0644);
76MODULE_PARM_DESC(dst_debug, "debug messages, default is 0 (no)");
77 40
78#define dprintk if (dst_debug) printk 41static unsigned int debug = 1;
42module_param(debug, int, 0644);
43MODULE_PARM_DESC(debug, "debug messages, default is 0 (yes)");
79 44
80#define DST_TYPE_IS_SAT 0 45static unsigned int dst_addons;
81#define DST_TYPE_IS_TERR 1 46module_param(dst_addons, int, 0644);
82#define DST_TYPE_IS_CABLE 2 47MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
83 48
84#define DST_TYPE_HAS_NEWTUNE 1 49#define dprintk if (debug) printk
85#define DST_TYPE_HAS_TS204 2
86#define DST_TYPE_HAS_SYMDIV 4
87 50
88#define HAS_LOCK 1 51#define HAS_LOCK 1
89#define ATTEMPT_TUNE 2 52#define ATTEMPT_TUNE 2
@@ -97,7 +60,7 @@ static void dst_packsize(struct dst_state* state, int psize)
97 bt878_device_control(state->bt, DST_IG_TS, &bits); 60 bt878_device_control(state->bt, DST_IG_TS, &bits);
98} 61}
99 62
100static int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh) 63int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay)
101{ 64{
102 union dst_gpio_packet enb; 65 union dst_gpio_packet enb;
103 union dst_gpio_packet bits; 66 union dst_gpio_packet bits;
@@ -105,26 +68,33 @@ static int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhig
105 68
106 enb.enb.mask = mask; 69 enb.enb.mask = mask;
107 enb.enb.enable = enbb; 70 enb.enb.enable = enbb;
71 if (verbose > 4)
72 dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__, mask, enbb, outhigh);
73
108 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) { 74 if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
109 dprintk("%s: dst_gpio_enb error (err == %i, mask == 0x%02x, enb == 0x%02x)\n", __FUNCTION__, err, mask, enbb); 75 dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__, err, mask, enbb);
110 return -EREMOTEIO; 76 return -EREMOTEIO;
111 } 77 }
112 78 udelay(1000);
113 /* because complete disabling means no output, no need to do output packet */ 79 /* because complete disabling means no output, no need to do output packet */
114 if (enbb == 0) 80 if (enbb == 0)
115 return 0; 81 return 0;
116 82
83 if (delay)
84 msleep(10);
85
117 bits.outp.mask = enbb; 86 bits.outp.mask = enbb;
118 bits.outp.highvals = outhigh; 87 bits.outp.highvals = outhigh;
119 88
120 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) { 89 if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
121 dprintk("%s: dst_gpio_outb error (err == %i, enbb == 0x%02x, outhigh == 0x%02x)\n", __FUNCTION__, err, enbb, outhigh); 90 dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__, err, enbb, outhigh);
122 return -EREMOTEIO; 91 return -EREMOTEIO;
123 } 92 }
124 return 0; 93 return 0;
125} 94}
95EXPORT_SYMBOL(dst_gpio_outb);
126 96
127static int dst_gpio_inb(struct dst_state *state, u8 * result) 97int dst_gpio_inb(struct dst_state *state, u8 * result)
128{ 98{
129 union dst_gpio_packet rd_packet; 99 union dst_gpio_packet rd_packet;
130 int err; 100 int err;
@@ -139,143 +109,225 @@ static int dst_gpio_inb(struct dst_state *state, u8 * result)
139 *result = (u8) rd_packet.rd.value; 109 *result = (u8) rd_packet.rd.value;
140 return 0; 110 return 0;
141} 111}
112EXPORT_SYMBOL(dst_gpio_inb);
142 113
143#define DST_I2C_ENABLE 1 114int rdc_reset_state(struct dst_state *state)
144#define DST_8820 2
145
146static int dst_reset8820(struct dst_state *state)
147{ 115{
148 int retval; 116 if (verbose > 1)
149 /* pull 8820 gpio pin low, wait, high, wait, then low */ 117 dprintk("%s: Resetting state machine\n", __FUNCTION__);
150 // dprintk ("%s: reset 8820\n", __FUNCTION__); 118
151 retval = dst_gpio_outb(state, DST_8820, DST_8820, 0); 119 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
152 if (retval < 0) 120 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
153 return retval; 121 return -1;
122 }
123
154 msleep(10); 124 msleep(10);
155 retval = dst_gpio_outb(state, DST_8820, DST_8820, DST_8820); 125
156 if (retval < 0) 126 if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
157 return retval; 127 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
158 /* wait for more feedback on what works here * 128 msleep(10);
159 msleep(10); 129 return -1;
160 retval = dst_gpio_outb(dst, DST_8820, DST_8820, 0); 130 }
161 if (retval < 0) 131
162 return retval;
163 */
164 return 0; 132 return 0;
165} 133}
134EXPORT_SYMBOL(rdc_reset_state);
166 135
167static int dst_i2c_enable(struct dst_state *state) 136int rdc_8820_reset(struct dst_state *state)
168{ 137{
169 int retval; 138 if (verbose > 1)
170 /* pull I2C enable gpio pin low, wait */ 139 dprintk("%s: Resetting DST\n", __FUNCTION__);
171 // dprintk ("%s: i2c enable\n", __FUNCTION__); 140
172 retval = dst_gpio_outb(state, ~0, DST_I2C_ENABLE, 0); 141 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
173 if (retval < 0) 142 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
174 return retval; 143 return -1;
175 // dprintk ("%s: i2c enable delay\n", __FUNCTION__); 144 }
176 msleep(33); 145 udelay(1000);
146 if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
147 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
148 return -1;
149 }
150
177 return 0; 151 return 0;
178} 152}
153EXPORT_SYMBOL(rdc_8820_reset);
179 154
180static int dst_i2c_disable(struct dst_state *state) 155int dst_pio_enable(struct dst_state *state)
181{ 156{
182 int retval; 157 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
183 /* release I2C enable gpio pin, wait */ 158 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
184 // dprintk ("%s: i2c disable\n", __FUNCTION__); 159 return -1;
185 retval = dst_gpio_outb(state, ~0, 0, 0); 160 }
186 if (retval < 0) 161 udelay(1000);
187 return retval; 162 return 0;
188 // dprintk ("%s: i2c disable delay\n", __FUNCTION__); 163}
189 msleep(33); 164EXPORT_SYMBOL(dst_pio_enable);
165
166int dst_pio_disable(struct dst_state *state)
167{
168 if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
169 dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
170 return -1;
171 }
172 if (state->type_flags & DST_TYPE_HAS_FW_1)
173 udelay(1000);
174
190 return 0; 175 return 0;
191} 176}
177EXPORT_SYMBOL(dst_pio_disable);
192 178
193static int dst_wait_dst_ready(struct dst_state *state) 179int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
194{ 180{
195 u8 reply; 181 u8 reply;
196 int retval;
197 int i; 182 int i;
183
198 for (i = 0; i < 200; i++) { 184 for (i = 0; i < 200; i++) {
199 retval = dst_gpio_inb(state, &reply); 185 if (dst_gpio_inb(state, &reply) < 0) {
200 if (retval < 0) 186 dprintk("%s: dst_gpio_inb ERROR !\n", __FUNCTION__);
201 return retval; 187 return -1;
202 if ((reply & DST_I2C_ENABLE) == 0) { 188 }
203 dprintk("%s: dst wait ready after %d\n", __FUNCTION__, i); 189
190 if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
191 if (verbose > 4)
192 dprintk("%s: dst wait ready after %d\n", __FUNCTION__, i);
204 return 1; 193 return 1;
205 } 194 }
206 msleep(10); 195 msleep(10);
207 } 196 }
208 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i); 197 if (verbose > 1)
198 dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i);
199
200 return 0;
201}
202EXPORT_SYMBOL(dst_wait_dst_ready);
203
204int dst_error_recovery(struct dst_state *state)
205{
206 dprintk("%s: Trying to return from previous errors...\n", __FUNCTION__);
207 dst_pio_disable(state);
208 msleep(10);
209 dst_pio_enable(state);
210 msleep(10);
211
209 return 0; 212 return 0;
210} 213}
214EXPORT_SYMBOL(dst_error_recovery);
215
216int dst_error_bailout(struct dst_state *state)
217{
218 dprintk("%s: Trying to bailout from previous error...\n", __FUNCTION__);
219 rdc_8820_reset(state);
220 dst_pio_disable(state);
221 msleep(10);
222
223 return 0;
224}
225EXPORT_SYMBOL(dst_error_bailout);
226
227
228int dst_comm_init(struct dst_state* state)
229{
230 if (verbose > 1)
231 dprintk ("%s: Initializing DST..\n", __FUNCTION__);
232 if ((dst_pio_enable(state)) < 0) {
233 dprintk("%s: PIO Enable Failed.\n", __FUNCTION__);
234 return -1;
235 }
236 if ((rdc_reset_state(state)) < 0) {
237 dprintk("%s: RDC 8820 State RESET Failed.\n", __FUNCTION__);
238 return -1;
239 }
240 if (state->type_flags & DST_TYPE_HAS_FW_1)
241 msleep(100);
242 else
243 msleep(5);
244
245 return 0;
246}
247EXPORT_SYMBOL(dst_comm_init);
248
211 249
212static int write_dst(struct dst_state *state, u8 * data, u8 len) 250int write_dst(struct dst_state *state, u8 *data, u8 len)
213{ 251{
214 struct i2c_msg msg = { 252 struct i2c_msg msg = {
215 .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len 253 .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len
216 }; 254 };
255
217 int err; 256 int err;
218 int cnt; 257 int cnt;
219 258 if (debug && (verbose > 4)) {
220 if (dst_debug && dst_verbose) {
221 u8 i; 259 u8 i;
222 dprintk("%s writing", __FUNCTION__); 260 if (verbose > 4) {
223 for (i = 0; i < len; i++) { 261 dprintk("%s writing", __FUNCTION__);
224 dprintk(" 0x%02x", data[i]); 262 for (i = 0; i < len; i++)
263 dprintk(" %02x", data[i]);
264 dprintk("\n");
225 } 265 }
226 dprintk("\n");
227 } 266 }
228 msleep(30); 267 for (cnt = 0; cnt < 2; cnt++) {
229 for (cnt = 0; cnt < 4; cnt++) {
230 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { 268 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
231 dprintk("%s: write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]); 269 dprintk("%s: _write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]);
232 dst_i2c_disable(state); 270 dst_error_recovery(state);
233 msleep(500);
234 dst_i2c_enable(state);
235 msleep(500);
236 continue; 271 continue;
237 } else 272 } else
238 break; 273 break;
239 } 274 }
240 if (cnt >= 4) 275
241 return -EREMOTEIO; 276 if (cnt >= 2) {
277 if (verbose > 1)
278 printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
279 dst_error_bailout(state);
280
281 return -1;
282 }
283
242 return 0; 284 return 0;
243} 285}
286EXPORT_SYMBOL(write_dst);
244 287
245static int read_dst(struct dst_state *state, u8 * ret, u8 len) 288int read_dst(struct dst_state *state, u8 * ret, u8 len)
246{ 289{
247 struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len }; 290 struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len };
248 int err; 291 int err;
249 int cnt; 292 int cnt;
250 293
251 for (cnt = 0; cnt < 4; cnt++) { 294 for (cnt = 0; cnt < 2; cnt++) {
252 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) { 295 if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
296
253 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]); 297 dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]);
254 dst_i2c_disable(state); 298 dst_error_recovery(state);
255 dst_i2c_enable(state); 299
256 continue; 300 continue;
257 } else 301 } else
258 break; 302 break;
259 } 303 }
260 if (cnt >= 4) 304 if (cnt >= 2) {
261 return -EREMOTEIO; 305 if (verbose > 1)
262 dprintk("%s reply is 0x%x\n", __FUNCTION__, ret[0]); 306 printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
263 if (dst_debug && dst_verbose) { 307 dst_error_bailout(state);
308
309 return -1;
310 }
311 if (debug && (verbose > 4)) {
312 dprintk("%s reply is 0x%x\n", __FUNCTION__, ret[0]);
264 for (err = 1; err < len; err++) 313 for (err = 1; err < len; err++)
265 dprintk(" 0x%x", ret[err]); 314 dprintk(" 0x%x", ret[err]);
266 if (err > 1) 315 if (err > 1)
267 dprintk("\n"); 316 dprintk("\n");
268 } 317 }
318
269 return 0; 319 return 0;
270} 320}
321EXPORT_SYMBOL(read_dst);
271 322
272static int dst_set_freq(struct dst_state *state, u32 freq) 323static int dst_set_freq(struct dst_state *state, u32 freq)
273{ 324{
274 u8 *val; 325 u8 *val;
275 326
276 state->frequency = freq; 327 state->frequency = freq;
328 if (debug > 4)
329 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
277 330
278 // dprintk("%s: set frequency %u\n", __FUNCTION__, freq);
279 if (state->dst_type == DST_TYPE_IS_SAT) { 331 if (state->dst_type == DST_TYPE_IS_SAT) {
280 freq = freq / 1000; 332 freq = freq / 1000;
281 if (freq < 950 || freq > 2150) 333 if (freq < 950 || freq > 2150)
@@ -398,7 +450,8 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
398 if (state->dst_type == DST_TYPE_IS_TERR) { 450 if (state->dst_type == DST_TYPE_IS_TERR) {
399 return 0; 451 return 0;
400 } 452 }
401 // dprintk("%s: set srate %u\n", __FUNCTION__, srate); 453 if (debug > 4)
454 dprintk("%s: set symrate %u\n", __FUNCTION__, srate);
402 srate /= 1000; 455 srate /= 1000;
403 val = &state->tx_tuna[0]; 456 val = &state->tx_tuna[0];
404 457
@@ -407,7 +460,10 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
407 sval <<= 20; 460 sval <<= 20;
408 do_div(sval, 88000); 461 do_div(sval, 88000);
409 symcalc = (u32) sval; 462 symcalc = (u32) sval;
410 // dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc); 463
464 if (debug > 4)
465 dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc);
466
411 val[5] = (u8) (symcalc >> 12); 467 val[5] = (u8) (symcalc >> 12);
412 val[6] = (u8) (symcalc >> 4); 468 val[6] = (u8) (symcalc >> 4);
413 val[7] = (u8) (symcalc << 4); 469 val[7] = (u8) (symcalc << 4);
@@ -422,7 +478,7 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
422 return 0; 478 return 0;
423} 479}
424 480
425static u8 dst_check_sum(u8 * buf, u32 len) 481u8 dst_check_sum(u8 * buf, u32 len)
426{ 482{
427 u32 i; 483 u32 i;
428 u8 val = 0; 484 u8 val = 0;
@@ -433,28 +489,7 @@ static u8 dst_check_sum(u8 * buf, u32 len)
433 } 489 }
434 return ((~val) + 1); 490 return ((~val) + 1);
435} 491}
436 492EXPORT_SYMBOL(dst_check_sum);
437struct dst_types {
438 char *mstr;
439 int offs;
440 u8 dst_type;
441 u32 type_flags;
442};
443
444static struct dst_types dst_tlist[] = {
445 {"DST-020", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV},
446 {"DST-030", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE},
447 {"DST-03T", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204},
448 {"DST-MOT", 0, DST_TYPE_IS_SAT, DST_TYPE_HAS_SYMDIV},
449 {"DST-CI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE},
450 {"DSTMCI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_NEWTUNE},
451 {"DSTFCI", 1, DST_TYPE_IS_SAT, DST_TYPE_HAS_NEWTUNE},
452 {"DCTNEW", 1, DST_TYPE_IS_CABLE, DST_TYPE_HAS_NEWTUNE},
453 {"DCT-CI", 1, DST_TYPE_IS_CABLE, DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_TS204},
454 {"DTTDIG", 1, DST_TYPE_IS_TERR, 0}
455};
456
457/* DCTNEW and DCT-CI are guesses */
458 493
459static void dst_type_flags_print(u32 type_flags) 494static void dst_type_flags_print(u32 type_flags)
460{ 495{
@@ -465,93 +500,270 @@ static void dst_type_flags_print(u32 type_flags)
465 printk(" 0x%x ts204", DST_TYPE_HAS_TS204); 500 printk(" 0x%x ts204", DST_TYPE_HAS_TS204);
466 if (type_flags & DST_TYPE_HAS_SYMDIV) 501 if (type_flags & DST_TYPE_HAS_SYMDIV)
467 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV); 502 printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
503 if (type_flags & DST_TYPE_HAS_FW_1)
504 printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
505 if (type_flags & DST_TYPE_HAS_FW_2)
506 printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
507 if (type_flags & DST_TYPE_HAS_FW_3)
508 printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
509// if ((type_flags & DST_TYPE_HAS_FW_BUILD) && new_fw)
510
468 printk("\n"); 511 printk("\n");
469} 512}
470 513
471static int dst_type_print(u8 type) 514
515static int dst_type_print (u8 type)
472{ 516{
473 char *otype; 517 char *otype;
474 switch (type) { 518 switch (type) {
475 case DST_TYPE_IS_SAT: 519 case DST_TYPE_IS_SAT:
476 otype = "satellite"; 520 otype = "satellite";
477 break; 521 break;
522
478 case DST_TYPE_IS_TERR: 523 case DST_TYPE_IS_TERR:
479 otype = "terrestrial"; 524 otype = "terrestrial";
480 break; 525 break;
526
481 case DST_TYPE_IS_CABLE: 527 case DST_TYPE_IS_CABLE:
482 otype = "cable"; 528 otype = "cable";
483 break; 529 break;
530
484 default: 531 default:
485 printk("%s: invalid dst type %d\n", __FUNCTION__, type); 532 printk("%s: invalid dst type %d\n", __FUNCTION__, type);
486 return -EINVAL; 533 return -EINVAL;
487 } 534 }
488 printk("DST type : %s\n", otype); 535 printk("DST type : %s\n", otype);
536
489 return 0; 537 return 0;
490} 538}
491 539
492static int dst_check_ci(struct dst_state *state) 540/*
541 Known cards list
542 Satellite
543 -------------------
544 200103A
545 VP-1020 DST-MOT LG(old), TS=188
546
547 VP-1020 DST-03T LG(new), TS=204
548 VP-1022 DST-03T LG(new), TS=204
549 VP-1025 DST-03T LG(new), TS=204
550
551 VP-1030 DSTMCI, LG(new), TS=188
552 VP-1032 DSTMCI, LG(new), TS=188
553
554 Cable
555 -------------------
556 VP-2030 DCT-CI, Samsung, TS=204
557 VP-2021 DCT-CI, Unknown, TS=204
558 VP-2031 DCT-CI, Philips, TS=188
559 VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
560 VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
561
562 Terrestrial
563 -------------------
564 VP-3050 DTTNXT TS=188
565 VP-3040 DTT-CI, Philips, TS=188
566 VP-3040 DTT-CI, Philips, TS=204
567
568 ATSC
569 -------------------
570 VP-3220 ATSCDI, TS=188
571 VP-3250 ATSCAD, TS=188
572
573*/
574
575struct dst_types dst_tlist[] = {
576 {
577 .device_id = "200103A",
578 .offset = 0,
579 .dst_type = DST_TYPE_IS_SAT,
580 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
581 .dst_feature = 0
582 }, /* obsolete */
583
584 {
585 .device_id = "DST-020",
586 .offset = 0,
587 .dst_type = DST_TYPE_IS_SAT,
588 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
589 .dst_feature = 0
590 }, /* obsolete */
591
592 {
593 .device_id = "DST-030",
594 .offset = 0,
595 .dst_type = DST_TYPE_IS_SAT,
596 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
597 .dst_feature = 0
598 }, /* obsolete */
599
600 {
601 .device_id = "DST-03T",
602 .offset = 0,
603 .dst_type = DST_TYPE_IS_SAT,
604 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
605 .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
606 | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO
607 },
608
609 {
610 .device_id = "DST-MOT",
611 .offset = 0,
612 .dst_type = DST_TYPE_IS_SAT,
613 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
614 .dst_feature = 0
615 }, /* obsolete */
616
617 {
618 .device_id = "DST-CI",
619 .offset = 1,
620 .dst_type = DST_TYPE_IS_SAT,
621 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
622 .dst_feature = DST_TYPE_HAS_CA
623 }, /* An OEM board */
624
625 {
626 .device_id = "DSTMCI",
627 .offset = 1,
628 .dst_type = DST_TYPE_IS_SAT,
629 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
630 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
631 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
632 },
633
634 {
635 .device_id = "DSTFCI",
636 .offset = 1,
637 .dst_type = DST_TYPE_IS_SAT,
638 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
639 .dst_feature = 0
640 }, /* unknown to vendor */
641
642 {
643 .device_id = "DCT-CI",
644 .offset = 1,
645 .dst_type = DST_TYPE_IS_CABLE,
646 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1
647 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
648 .dst_feature = DST_TYPE_HAS_CA
649 },
650
651 {
652 .device_id = "DCTNEW",
653 .offset = 1,
654 .dst_type = DST_TYPE_IS_CABLE,
655 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3,
656 .dst_feature = 0
657 },
658
659 {
660 .device_id = "DTT-CI",
661 .offset = 1,
662 .dst_type = DST_TYPE_IS_TERR,
663 .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
664 .dst_feature = 0
665 },
666
667 {
668 .device_id = "DTTDIG",
669 .offset = 1,
670 .dst_type = DST_TYPE_IS_TERR,
671 .type_flags = DST_TYPE_HAS_FW_2,
672 .dst_feature = 0
673 },
674
675 {
676 .device_id = "DTTNXT",
677 .offset = 1,
678 .dst_type = DST_TYPE_IS_TERR,
679 .type_flags = DST_TYPE_HAS_FW_2,
680 .dst_feature = DST_TYPE_HAS_ANALOG
681 },
682
683 {
684 .device_id = "ATSCDI",
685 .offset = 1,
686 .dst_type = DST_TYPE_IS_ATSC,
687 .type_flags = DST_TYPE_HAS_FW_2,
688 .dst_feature = 0
689 },
690
691 {
692 .device_id = "ATSCAD",
693 .offset = 1,
694 .dst_type = DST_TYPE_IS_ATSC,
695 .type_flags = DST_TYPE_HAS_FW_2,
696 .dst_feature = 0
697 },
698
699 { }
700
701};
702
703
704static int dst_get_device_id(struct dst_state *state)
493{ 705{
494 u8 txbuf[8]; 706 u8 reply;
495 u8 rxbuf[8]; 707
496 int retval;
497 int i; 708 int i;
498 struct dst_types *dsp; 709 struct dst_types *p_dst_type;
499 u8 use_dst_type; 710 u8 use_dst_type = 0;
500 u32 use_type_flags; 711 u32 use_type_flags = 0;
501 712
502 memset(txbuf, 0, sizeof(txbuf)); 713 static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
503 txbuf[1] = 6;
504 txbuf[7] = dst_check_sum(txbuf, 7);
505 714
506 dst_i2c_enable(state); 715 device_type[7] = dst_check_sum(device_type, 7);
507 dst_reset8820(state); 716
508 retval = write_dst(state, txbuf, 8); 717 if (write_dst(state, device_type, FIXED_COMM))
509 if (retval < 0) { 718 return -1; /* Write failed */
510 dst_i2c_disable(state); 719
511 dprintk("%s: write not successful, maybe no card?\n", __FUNCTION__); 720 if ((dst_pio_disable(state)) < 0)
512 return retval; 721 return -1;
513 } 722
514 msleep(3); 723 if (read_dst(state, &reply, GET_ACK))
515 retval = read_dst(state, rxbuf, 1); 724 return -1; /* Read failure */
516 dst_i2c_disable(state); 725
517 if (retval < 0) { 726 if (reply != ACK) {
518 dprintk("%s: read not successful, maybe no card?\n", __FUNCTION__); 727 dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__, reply);
519 return retval; 728 return -1; /* Unack'd write */
520 }
521 if (rxbuf[0] != 0xff) {
522 dprintk("%s: write reply not 0xff, not ci (%02x)\n", __FUNCTION__, rxbuf[0]);
523 return retval;
524 }
525 if (!dst_wait_dst_ready(state))
526 return 0;
527 // dst_i2c_enable(i2c); Dimitri
528 retval = read_dst(state, rxbuf, 8);
529 dst_i2c_disable(state);
530 if (retval < 0) {
531 dprintk("%s: read not successful\n", __FUNCTION__);
532 return retval;
533 } 729 }
534 if (rxbuf[7] != dst_check_sum(rxbuf, 7)) { 730
535 dprintk("%s: checksum failure\n", __FUNCTION__); 731 if (!dst_wait_dst_ready(state, DEVICE_INIT))
536 return retval; 732 return -1; /* DST not ready yet */
733
734 if (read_dst(state, state->rxbuffer, FIXED_COMM))
735 return -1;
736
737 dst_pio_disable(state);
738
739 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
740 dprintk("%s: Checksum failure! \n", __FUNCTION__);
741 return -1; /* Checksum failure */
537 } 742 }
538 rxbuf[7] = '\0'; 743
539 for (i = 0, dsp = &dst_tlist[0]; i < sizeof(dst_tlist) / sizeof(dst_tlist[0]); i++, dsp++) { 744 state->rxbuffer[7] = '\0';
540 if (!strncmp(&rxbuf[dsp->offs], dsp->mstr, strlen(dsp->mstr))) { 745
541 use_type_flags = dsp->type_flags; 746 for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE (dst_tlist); i++, p_dst_type++) {
542 use_dst_type = dsp->dst_type; 747 if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
543 printk("%s: recognize %s\n", __FUNCTION__, dsp->mstr); 748 use_type_flags = p_dst_type->type_flags;
749 use_dst_type = p_dst_type->dst_type;
750
751 /* Card capabilities */
752 state->dst_hw_cap = p_dst_type->dst_feature;
753 printk ("%s: Recognise [%s]\n", __FUNCTION__, p_dst_type->device_id);
754
544 break; 755 break;
545 } 756 }
546 } 757 }
547 if (i >= sizeof(dst_tlist) / sizeof(dst_tlist[0])) { 758
548 printk("%s: unable to recognize %s or %s\n", __FUNCTION__, &rxbuf[0], &rxbuf[1]); 759 if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
549 printk("%s please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__); 760 printk("%s: Unable to recognize %s or %s\n", __FUNCTION__, &state->rxbuffer[0], &state->rxbuffer[1]);
761 printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__);
550 use_dst_type = DST_TYPE_IS_SAT; 762 use_dst_type = DST_TYPE_IS_SAT;
551 use_type_flags = DST_TYPE_HAS_SYMDIV; 763 use_type_flags = DST_TYPE_HAS_SYMDIV;
552 } 764 }
553 dst_type_print(use_dst_type);
554 765
766 dst_type_print(use_dst_type);
555 state->type_flags = use_type_flags; 767 state->type_flags = use_type_flags;
556 state->dst_type = use_dst_type; 768 state->dst_type = use_dst_type;
557 dst_type_flags_print(state->type_flags); 769 dst_type_flags_print(state->type_flags);
@@ -559,50 +771,102 @@ static int dst_check_ci(struct dst_state *state)
559 if (state->type_flags & DST_TYPE_HAS_TS204) { 771 if (state->type_flags & DST_TYPE_HAS_TS204) {
560 dst_packsize(state, 204); 772 dst_packsize(state, 204);
561 } 773 }
774
562 return 0; 775 return 0;
563} 776}
564 777
565static int dst_command(struct dst_state* state, u8 * data, u8 len) 778static int dst_probe(struct dst_state *state)
779{
780 if ((rdc_8820_reset(state)) < 0) {
781 dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__);
782 return -1;
783 }
784 if (dst_addons & DST_TYPE_HAS_CA)
785 msleep(4000);
786 else
787 msleep(100);
788
789 if ((dst_comm_init(state)) < 0) {
790 dprintk("%s: DST Initialization Failed.\n", __FUNCTION__);
791 return -1;
792 }
793 msleep(100);
794 if (dst_get_device_id(state) < 0) {
795 dprintk("%s: unknown device.\n", __FUNCTION__);
796 return -1;
797 }
798
799 return 0;
800}
801
802int dst_command(struct dst_state* state, u8 * data, u8 len)
566{ 803{
567 int retval;
568 u8 reply; 804 u8 reply;
805 if ((dst_comm_init(state)) < 0) {
806 dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__);
807 return -1;
808 }
569 809
570 dst_i2c_enable(state); 810 if (write_dst(state, data, len)) {
571 dst_reset8820(state); 811 if (verbose > 1)
572 retval = write_dst(state, data, len); 812 dprintk("%s: Tring to recover.. \n", __FUNCTION__);
573 if (retval < 0) { 813 if ((dst_error_recovery(state)) < 0) {
574 dst_i2c_disable(state); 814 dprintk("%s: Recovery Failed.\n", __FUNCTION__);
575 dprintk("%s: write not successful\n", __FUNCTION__); 815 return -1;
576 return retval; 816 }
817 return -1;
577 } 818 }
578 msleep(33); 819 if ((dst_pio_disable(state)) < 0) {
579 retval = read_dst(state, &reply, 1); 820 dprintk("%s: PIO Disable Failed.\n", __FUNCTION__);
580 dst_i2c_disable(state); 821 return -1;
581 if (retval < 0) {
582 dprintk("%s: read verify not successful\n", __FUNCTION__);
583 return retval;
584 } 822 }
585 if (reply != 0xff) { 823 if (state->type_flags & DST_TYPE_HAS_FW_1)
586 dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__, reply); 824 udelay(3000);
587 return 0; 825
826 if (read_dst(state, &reply, GET_ACK)) {
827 if (verbose > 1)
828 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
829 if ((dst_error_recovery(state)) < 0) {
830 dprintk("%s: Recovery Failed.\n", __FUNCTION__);
831 return -1;
832 }
833 return -1;
834 }
835
836 if (reply != ACK) {
837 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
838 return -1;
588 } 839 }
589 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3)) 840 if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
590 return 0; 841 return 0;
591 if (!dst_wait_dst_ready(state)) 842
592 return 0; 843// udelay(3000);
593 // dst_i2c_enable(i2c); Per dimitri 844 if (state->type_flags & DST_TYPE_HAS_FW_1)
594 retval = read_dst(state, state->rxbuffer, 8); 845 udelay(3000);
595 dst_i2c_disable(state); 846 else
596 if (retval < 0) { 847 udelay(2000);
597 dprintk("%s: read not successful\n", __FUNCTION__); 848
598 return 0; 849 if (!dst_wait_dst_ready(state, NO_DELAY))
850 return -1;
851
852 if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
853 if (verbose > 1)
854 dprintk("%s: Trying to recover.. \n", __FUNCTION__);
855 if ((dst_error_recovery(state)) < 0) {
856 dprintk("%s: Recovery failed.\n", __FUNCTION__);
857 return -1;
858 }
859 return -1;
599 } 860 }
861
600 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) { 862 if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
601 dprintk("%s: checksum failure\n", __FUNCTION__); 863 dprintk("%s: checksum failure\n", __FUNCTION__);
602 return 0; 864 return -1;
603 } 865 }
866
604 return 0; 867 return 0;
605} 868}
869EXPORT_SYMBOL(dst_command);
606 870
607static int dst_get_signal(struct dst_state* state) 871static int dst_get_signal(struct dst_state* state)
608{ 872{
@@ -642,37 +906,38 @@ static int dst_tone_power_cmd(struct dst_state* state)
642 if (state->dst_type == DST_TYPE_IS_TERR) 906 if (state->dst_type == DST_TYPE_IS_TERR)
643 return 0; 907 return 0;
644 908
645 if (state->voltage == SEC_VOLTAGE_OFF) 909 paket[4] = state->tx_tuna[4];
646 paket[4] = 0; 910 paket[2] = state->tx_tuna[2];
647 else 911 paket[3] = state->tx_tuna[3];
648 paket[4] = 1; 912 paket[7] = dst_check_sum (paket, 7);
649 if (state->tone == SEC_TONE_ON)
650 paket[2] = state->k22;
651 else
652 paket[2] = 0;
653 paket[7] = dst_check_sum(&paket[0], 7);
654 dst_command(state, paket, 8); 913 dst_command(state, paket, 8);
914
655 return 0; 915 return 0;
656} 916}
657 917
658static int dst_get_tuna(struct dst_state* state) 918static int dst_get_tuna(struct dst_state* state)
659{ 919{
660 int retval; 920 int retval;
921
661 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) 922 if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
662 return 0; 923 return 0;
924
663 state->diseq_flags &= ~(HAS_LOCK); 925 state->diseq_flags &= ~(HAS_LOCK);
664 if (!dst_wait_dst_ready(state)) 926 if (!dst_wait_dst_ready(state, NO_DELAY))
665 return 0; 927 return 0;
928
666 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 929 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
667 /* how to get variable length reply ???? */ 930 /* how to get variable length reply ???? */
668 retval = read_dst(state, state->rx_tuna, 10); 931 retval = read_dst(state, state->rx_tuna, 10);
669 } else { 932 } else {
670 retval = read_dst(state, &state->rx_tuna[2], 8); 933 retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
671 } 934 }
935
672 if (retval < 0) { 936 if (retval < 0) {
673 dprintk("%s: read not successful\n", __FUNCTION__); 937 dprintk("%s: read not successful\n", __FUNCTION__);
674 return 0; 938 return 0;
675 } 939 }
940
676 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 941 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
677 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) { 942 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
678 dprintk("%s: checksum failure?\n", __FUNCTION__); 943 dprintk("%s: checksum failure?\n", __FUNCTION__);
@@ -705,11 +970,13 @@ static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
705 970
706static int dst_write_tuna(struct dvb_frontend* fe) 971static int dst_write_tuna(struct dvb_frontend* fe)
707{ 972{
708 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 973 struct dst_state* state = fe->demodulator_priv;
709 int retval; 974 int retval;
710 u8 reply; 975 u8 reply;
711 976
712 dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags); 977 if (debug > 4)
978 dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags);
979
713 state->decode_freq = 0; 980 state->decode_freq = 0;
714 state->decode_lock = state->decode_strength = state->decode_snr = 0; 981 state->decode_lock = state->decode_strength = state->decode_snr = 0;
715 if (state->dst_type == DST_TYPE_IS_SAT) { 982 if (state->dst_type == DST_TYPE_IS_SAT) {
@@ -717,32 +984,41 @@ static int dst_write_tuna(struct dvb_frontend* fe)
717 dst_set_voltage(fe, SEC_VOLTAGE_13); 984 dst_set_voltage(fe, SEC_VOLTAGE_13);
718 } 985 }
719 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE); 986 state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
720 dst_i2c_enable(state); 987
988 if ((dst_comm_init(state)) < 0) {
989 dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__);
990 return -1;
991 }
992
721 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) { 993 if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
722 dst_reset8820(state);
723 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9); 994 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
724 retval = write_dst(state, &state->tx_tuna[0], 10); 995 retval = write_dst(state, &state->tx_tuna[0], 10);
996
725 } else { 997 } else {
726 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7); 998 state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
727 retval = write_dst(state, &state->tx_tuna[2], 8); 999 retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
728 } 1000 }
729 if (retval < 0) { 1001 if (retval < 0) {
730 dst_i2c_disable(state); 1002 dst_pio_disable(state);
731 dprintk("%s: write not successful\n", __FUNCTION__); 1003 dprintk("%s: write not successful\n", __FUNCTION__);
732 return retval; 1004 return retval;
733 } 1005 }
734 msleep(3); 1006
735 retval = read_dst(state, &reply, 1); 1007 if ((dst_pio_disable(state)) < 0) {
736 dst_i2c_disable(state); 1008 dprintk("%s: DST PIO disable failed !\n", __FUNCTION__);
737 if (retval < 0) { 1009 return -1;
738 dprintk("%s: read verify not successful\n", __FUNCTION__);
739 return retval;
740 } 1010 }
741 if (reply != 0xff) { 1011
742 dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__, reply); 1012 if ((read_dst(state, &reply, GET_ACK) < 0)) {
1013 dprintk("%s: read verify not successful.\n", __FUNCTION__);
1014 return -1;
1015 }
1016 if (reply != ACK) {
1017 dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
743 return 0; 1018 return 0;
744 } 1019 }
745 state->diseq_flags |= ATTEMPT_TUNE; 1020 state->diseq_flags |= ATTEMPT_TUNE;
1021
746 return dst_get_tuna(state); 1022 return dst_get_tuna(state);
747} 1023}
748 1024
@@ -762,10 +1038,10 @@ static int dst_write_tuna(struct dvb_frontend* fe)
762 1038
763static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) 1039static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
764{ 1040{
765 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1041 struct dst_state* state = fe->demodulator_priv;
766 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec }; 1042 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
767 1043
768 if (state->dst_type == DST_TYPE_IS_TERR) 1044 if (state->dst_type != DST_TYPE_IS_SAT)
769 return 0; 1045 return 0;
770 1046
771 if (cmd->msg_len == 0 || cmd->msg_len > 4) 1047 if (cmd->msg_len == 0 || cmd->msg_len > 4)
@@ -778,73 +1054,91 @@ static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd*
778 1054
779static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 1055static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
780{ 1056{
781 u8 *val;
782 int need_cmd; 1057 int need_cmd;
783 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1058 struct dst_state* state = fe->demodulator_priv;
784 1059
785 state->voltage = voltage; 1060 state->voltage = voltage;
786 1061
787 if (state->dst_type == DST_TYPE_IS_TERR) 1062 if (state->dst_type != DST_TYPE_IS_SAT)
788 return 0; 1063 return 0;
789 1064
790 need_cmd = 0; 1065 need_cmd = 0;
791 val = &state->tx_tuna[0];
792 val[8] &= ~0x40;
793 switch (voltage) { 1066 switch (voltage) {
794 case SEC_VOLTAGE_13: 1067 case SEC_VOLTAGE_13:
795 if ((state->diseq_flags & HAS_POWER) == 0) 1068 case SEC_VOLTAGE_18:
796 need_cmd = 1; 1069 if ((state->diseq_flags & HAS_POWER) == 0)
797 state->diseq_flags |= HAS_POWER; 1070 need_cmd = 1;
798 break; 1071 state->diseq_flags |= HAS_POWER;
799 case SEC_VOLTAGE_18: 1072 state->tx_tuna[4] = 0x01;
800 if ((state->diseq_flags & HAS_POWER) == 0) 1073 break;
1074
1075 case SEC_VOLTAGE_OFF:
801 need_cmd = 1; 1076 need_cmd = 1;
802 state->diseq_flags |= HAS_POWER; 1077 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
803 val[8] |= 0x40; 1078 state->tx_tuna[4] = 0x00;
804 break; 1079 break;
805 case SEC_VOLTAGE_OFF: 1080
806 need_cmd = 1; 1081 default:
807 state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE); 1082 return -EINVAL;
808 break;
809 default:
810 return -EINVAL;
811 } 1083 }
812 if (need_cmd) { 1084 if (need_cmd)
813 dst_tone_power_cmd(state); 1085 dst_tone_power_cmd(state);
814 } 1086
815 return 0; 1087 return 0;
816} 1088}
817 1089
818static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 1090static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
819{ 1091{
820 u8 *val; 1092 struct dst_state* state = fe->demodulator_priv;
821 struct dst_state* state = (struct dst_state*) fe->demodulator_priv;
822 1093
823 state->tone = tone; 1094 state->tone = tone;
824 1095
825 if (state->dst_type == DST_TYPE_IS_TERR) 1096 if (state->dst_type != DST_TYPE_IS_SAT)
826 return 0; 1097 return 0;
827 1098
828 val = &state->tx_tuna[0]; 1099 switch (tone) {
1100 case SEC_TONE_OFF:
1101 state->tx_tuna[2] = 0xff;
1102 break;
829 1103
830 val[8] &= ~0x1; 1104 case SEC_TONE_ON:
1105 state->tx_tuna[2] = 0x02;
1106 break;
831 1107
832 switch (tone) { 1108 default:
833 case SEC_TONE_OFF: 1109 return -EINVAL;
834 break;
835 case SEC_TONE_ON:
836 val[8] |= 1;
837 break;
838 default:
839 return -EINVAL;
840 } 1110 }
841 dst_tone_power_cmd(state); 1111 dst_tone_power_cmd(state);
1112
1113 return 0;
1114}
1115
1116static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1117{
1118 struct dst_state *state = fe->demodulator_priv;
1119
1120 if (state->dst_type != DST_TYPE_IS_SAT)
1121 return 0;
1122
1123 state->minicmd = minicmd;
1124
1125 switch (minicmd) {
1126 case SEC_MINI_A:
1127 state->tx_tuna[3] = 0x02;
1128 break;
1129 case SEC_MINI_B:
1130 state->tx_tuna[3] = 0xff;
1131 break;
1132 }
1133 dst_tone_power_cmd(state);
1134
842 return 0; 1135 return 0;
843} 1136}
844 1137
1138
845static int dst_init(struct dvb_frontend* fe) 1139static int dst_init(struct dvb_frontend* fe)
846{ 1140{
847 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1141 struct dst_state* state = fe->demodulator_priv;
848 static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 }; 1142 static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 };
849 static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 }; 1143 static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 };
850 static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1144 static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
@@ -876,7 +1170,7 @@ static int dst_init(struct dvb_frontend* fe)
876 1170
877static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status) 1171static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
878{ 1172{
879 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1173 struct dst_state* state = fe->demodulator_priv;
880 1174
881 *status = 0; 1175 *status = 0;
882 if (state->diseq_flags & HAS_LOCK) { 1176 if (state->diseq_flags & HAS_LOCK) {
@@ -890,7 +1184,7 @@ static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
890 1184
891static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength) 1185static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength)
892{ 1186{
893 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1187 struct dst_state* state = fe->demodulator_priv;
894 1188
895 dst_get_signal(state); 1189 dst_get_signal(state);
896 *strength = state->decode_strength; 1190 *strength = state->decode_strength;
@@ -900,7 +1194,7 @@ static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength)
900 1194
901static int dst_read_snr(struct dvb_frontend* fe, u16* snr) 1195static int dst_read_snr(struct dvb_frontend* fe, u16* snr)
902{ 1196{
903 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1197 struct dst_state* state = fe->demodulator_priv;
904 1198
905 dst_get_signal(state); 1199 dst_get_signal(state);
906 *snr = state->decode_snr; 1200 *snr = state->decode_snr;
@@ -910,13 +1204,19 @@ static int dst_read_snr(struct dvb_frontend* fe, u16* snr)
910 1204
911static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 1205static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
912{ 1206{
913 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1207 struct dst_state* state = fe->demodulator_priv;
914 1208
915 dst_set_freq(state, p->frequency); 1209 dst_set_freq(state, p->frequency);
1210 if (verbose > 4)
1211 dprintk("Set Frequency = [%d]\n", p->frequency);
1212
916 dst_set_inversion(state, p->inversion); 1213 dst_set_inversion(state, p->inversion);
917 if (state->dst_type == DST_TYPE_IS_SAT) { 1214 if (state->dst_type == DST_TYPE_IS_SAT) {
918 dst_set_fec(state, p->u.qpsk.fec_inner); 1215 dst_set_fec(state, p->u.qpsk.fec_inner);
919 dst_set_symbolrate(state, p->u.qpsk.symbol_rate); 1216 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
1217 if (verbose > 4)
1218 dprintk("Set Symbolrate = [%d]\n", p->u.qpsk.symbol_rate);
1219
920 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1220 } else if (state->dst_type == DST_TYPE_IS_TERR) {
921 dst_set_bandwidth(state, p->u.ofdm.bandwidth); 1221 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
922 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1222 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
@@ -930,7 +1230,7 @@ static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
930 1230
931static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 1231static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
932{ 1232{
933 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1233 struct dst_state* state = fe->demodulator_priv;
934 1234
935 p->frequency = state->decode_freq; 1235 p->frequency = state->decode_freq;
936 p->inversion = state->inversion; 1236 p->inversion = state->inversion;
@@ -950,7 +1250,7 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
950 1250
951static void dst_release(struct dvb_frontend* fe) 1251static void dst_release(struct dvb_frontend* fe)
952{ 1252{
953 struct dst_state* state = (struct dst_state*) fe->demodulator_priv; 1253 struct dst_state* state = fe->demodulator_priv;
954 kfree(state); 1254 kfree(state);
955} 1255}
956 1256
@@ -958,50 +1258,47 @@ static struct dvb_frontend_ops dst_dvbt_ops;
958static struct dvb_frontend_ops dst_dvbs_ops; 1258static struct dvb_frontend_ops dst_dvbs_ops;
959static struct dvb_frontend_ops dst_dvbc_ops; 1259static struct dvb_frontend_ops dst_dvbc_ops;
960 1260
961struct dvb_frontend* dst_attach(const struct dst_config* config, 1261struct dst_state* dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
962 struct i2c_adapter* i2c,
963 struct bt878 *bt)
964{ 1262{
965 struct dst_state* state = NULL;
966
967 /* allocate memory for the internal state */
968 state = (struct dst_state*) kmalloc(sizeof(struct dst_state), GFP_KERNEL);
969 if (state == NULL) goto error;
970 1263
971 /* setup the state */ 1264 /* check if the ASIC is there */
972 state->config = config; 1265 if (dst_probe(state) < 0) {
973 state->i2c = i2c; 1266 if (state)
974 state->bt = bt; 1267 kfree(state);
975
976 /* check if the demod is there */
977 if (dst_check_ci(state) < 0) goto error;
978 1268
1269 return NULL;
1270 }
979 /* determine settings based on type */ 1271 /* determine settings based on type */
980 switch (state->dst_type) { 1272 switch (state->dst_type) {
981 case DST_TYPE_IS_TERR: 1273 case DST_TYPE_IS_TERR:
982 memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops)); 1274 memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
983 break; 1275 break;
1276
984 case DST_TYPE_IS_CABLE: 1277 case DST_TYPE_IS_CABLE:
985 memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops)); 1278 memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
986 break; 1279 break;
1280
987 case DST_TYPE_IS_SAT: 1281 case DST_TYPE_IS_SAT:
988 memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops)); 1282 memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
989 break; 1283 break;
1284
990 default: 1285 default:
991 printk("dst: unknown frontend type. please report to the LinuxTV.org DVB mailinglist.\n"); 1286 printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__);
992 goto error; 1287 if (state)
1288 kfree(state);
1289
1290 return NULL;
993 } 1291 }
994 1292
995 /* create dvb_frontend */ 1293 /* create dvb_frontend */
996 state->frontend.ops = &state->ops; 1294 state->frontend.ops = &state->ops;
997 state->frontend.demodulator_priv = state; 1295 state->frontend.demodulator_priv = state;
998 return &state->frontend;
999 1296
1000error: 1297 return state; /* Manu (DST is a card not a frontend) */
1001 kfree(state);
1002 return NULL;
1003} 1298}
1004 1299
1300EXPORT_SYMBOL(dst_attach);
1301
1005static struct dvb_frontend_ops dst_dvbt_ops = { 1302static struct dvb_frontend_ops dst_dvbt_ops = {
1006 1303
1007 .info = { 1304 .info = {
@@ -1051,6 +1348,7 @@ static struct dvb_frontend_ops dst_dvbs_ops = {
1051 .read_signal_strength = dst_read_signal_strength, 1348 .read_signal_strength = dst_read_signal_strength,
1052 .read_snr = dst_read_snr, 1349 .read_snr = dst_read_snr,
1053 1350
1351 .diseqc_send_burst = dst_send_burst,
1054 .diseqc_send_master_cmd = dst_set_diseqc, 1352 .diseqc_send_master_cmd = dst_set_diseqc,
1055 .set_voltage = dst_set_voltage, 1353 .set_voltage = dst_set_voltage,
1056 .set_tone = dst_set_tone, 1354 .set_tone = dst_set_tone,
@@ -1082,8 +1380,7 @@ static struct dvb_frontend_ops dst_dvbc_ops = {
1082 .read_snr = dst_read_snr, 1380 .read_snr = dst_read_snr,
1083}; 1381};
1084 1382
1383
1085MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver"); 1384MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
1086MODULE_AUTHOR("Jamie Honan"); 1385MODULE_AUTHOR("Jamie Honan, Manu Abraham");
1087MODULE_LICENSE("GPL"); 1386MODULE_LICENSE("GPL");
1088
1089EXPORT_SYMBOL(dst_attach);
diff --git a/drivers/media/dvb/bt8xx/dst.h b/drivers/media/dvb/bt8xx/dst.h
deleted file mode 100644
index bcb418c5c121..000000000000
--- a/drivers/media/dvb/bt8xx/dst.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 Frontend-driver for TwinHan DST Frontend
3
4 Copyright (C) 2003 Jamie Honan
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#ifndef DST_H
24#define DST_H
25
26#include <linux/dvb/frontend.h>
27#include <linux/device.h>
28#include "bt878.h"
29
30struct dst_config
31{
32 /* the demodulator's i2c address */
33 u8 demod_address;
34};
35
36extern struct dvb_frontend* dst_attach(const struct dst_config* config,
37 struct i2c_adapter* i2c,
38 struct bt878 *bt);
39
40#endif // DST_H
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
new file mode 100644
index 000000000000..d781504cc2fa
--- /dev/null
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -0,0 +1,861 @@
1/*
2 CA-driver for TwinHan DST Frontend/Card
3
4 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/string.h>
27
28#include <linux/dvb/ca.h>
29#include "dvbdev.h"
30#include "dvb_frontend.h"
31
32#include "dst_ca.h"
33#include "dst_common.h"
34
35static unsigned int verbose = 1;
36module_param(verbose, int, 0644);
37MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
38
39static unsigned int debug = 1;
40module_param(debug, int, 0644);
41MODULE_PARM_DESC(debug, "debug messages, default is 1 (yes)");
42
43#define dprintk if (debug) printk
44
45/* Need some more work */
46static int ca_set_slot_descr(void)
47{
48 /* We could make this more graceful ? */
49 return -EOPNOTSUPP;
50}
51
52/* Need some more work */
53static int ca_set_pid(void)
54{
55 /* We could make this more graceful ? */
56 return -EOPNOTSUPP;
57}
58
59
60static int put_checksum(u8 *check_string, int length)
61{
62 u8 i = 0, checksum = 0;
63
64 if (verbose > 3) {
65 dprintk("%s: ========================= Checksum calculation ===========================\n", __FUNCTION__);
66 dprintk("%s: String Length=[0x%02x]\n", __FUNCTION__, length);
67
68 dprintk("%s: String=[", __FUNCTION__);
69 }
70 while (i < length) {
71 if (verbose > 3)
72 dprintk(" %02x", check_string[i]);
73 checksum += check_string[i];
74 i++;
75 }
76 if (verbose > 3) {
77 dprintk(" ]\n");
78 dprintk("%s: Sum=[%02x]\n", __FUNCTION__, checksum);
79 }
80 check_string[length] = ~checksum + 1;
81 if (verbose > 3) {
82 dprintk("%s: Checksum=[%02x]\n", __FUNCTION__, check_string[length]);
83 dprintk("%s: ==========================================================================\n", __FUNCTION__);
84 }
85
86 return 0;
87}
88
89static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8 len, int read)
90{
91 u8 reply;
92
93 dst_comm_init(state);
94 msleep(65);
95
96 if (write_dst(state, data, len)) {
97 dprintk("%s: Write not successful, trying to recover\n", __FUNCTION__);
98 dst_error_recovery(state);
99 return -1;
100 }
101
102 if ((dst_pio_disable(state)) < 0) {
103 dprintk("%s: DST PIO disable failed.\n", __FUNCTION__);
104 return -1;
105 }
106
107 if (read_dst(state, &reply, GET_ACK) < 0) {
108 dprintk("%s: Read not successful, trying to recover\n", __FUNCTION__);
109 dst_error_recovery(state);
110 return -1;
111 }
112
113 if (read) {
114 if (! dst_wait_dst_ready(state, LONG_DELAY)) {
115 dprintk("%s: 8820 not ready\n", __FUNCTION__);
116 return -1;
117 }
118
119 if (read_dst(state, ca_string, 128) < 0) { /* Try to make this dynamic */
120 dprintk("%s: Read not successful, trying to recover\n", __FUNCTION__);
121 dst_error_recovery(state);
122 return -1;
123 }
124 }
125
126 return 0;
127}
128
129
130static int dst_put_ci(struct dst_state *state, u8 *data, int len, u8 *ca_string, int read)
131{
132 u8 dst_ca_comm_err = 0;
133
134 while (dst_ca_comm_err < RETRIES) {
135 dst_comm_init(state);
136 if (verbose > 2)
137 dprintk("%s: Put Command\n", __FUNCTION__);
138 if (dst_ci_command(state, data, ca_string, len, read)) { // If error
139 dst_error_recovery(state);
140 dst_ca_comm_err++; // work required here.
141 }
142 break;
143 }
144
145 return 0;
146}
147
148
149
150static int ca_get_app_info(struct dst_state *state)
151{
152 static u8 command[8] = {0x07, 0x40, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff};
153
154 put_checksum(&command[0], command[0]);
155 if ((dst_put_ci(state, command, sizeof(command), state->messages, GET_REPLY)) < 0) {
156 dprintk("%s: -->dst_put_ci FAILED !\n", __FUNCTION__);
157 return -1;
158 }
159 if (verbose > 1) {
160 dprintk("%s: -->dst_put_ci SUCCESS !\n", __FUNCTION__);
161
162 dprintk("%s: ================================ CI Module Application Info ======================================\n", __FUNCTION__);
163 dprintk("%s: Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]\n",
164 __FUNCTION__, state->messages[7], (state->messages[8] << 8) | state->messages[9],
165 (state->messages[10] << 8) | state->messages[11], __FUNCTION__, (char *)(&state->messages[12]));
166 dprintk("%s: ==================================================================================================\n", __FUNCTION__);
167 }
168
169 return 0;
170}
171
172static int ca_get_slot_caps(struct dst_state *state, struct ca_caps *p_ca_caps, void *arg)
173{
174 int i;
175 u8 slot_cap[256];
176 static u8 slot_command[8] = {0x07, 0x40, 0x02, 0x00, 0x02, 0x00, 0x00, 0xff};
177
178 put_checksum(&slot_command[0], slot_command[0]);
179 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_cap, GET_REPLY)) < 0) {
180 dprintk("%s: -->dst_put_ci FAILED !\n", __FUNCTION__);
181 return -1;
182 }
183 if (verbose > 1)
184 dprintk("%s: -->dst_put_ci SUCCESS !\n", __FUNCTION__);
185
186 /* Will implement the rest soon */
187
188 if (verbose > 1) {
189 dprintk("%s: Slot cap = [%d]\n", __FUNCTION__, slot_cap[7]);
190 dprintk("===================================\n");
191 for (i = 0; i < 8; i++)
192 dprintk(" %d", slot_cap[i]);
193 dprintk("\n");
194 }
195
196 p_ca_caps->slot_num = 1;
197 p_ca_caps->slot_type = 1;
198 p_ca_caps->descr_num = slot_cap[7];
199 p_ca_caps->descr_type = 1;
200
201
202 if (copy_to_user((struct ca_caps *)arg, p_ca_caps, sizeof (struct ca_caps))) {
203 return -EFAULT;
204 }
205
206 return 0;
207}
208
209/* Need some more work */
210static int ca_get_slot_descr(struct dst_state *state, struct ca_msg *p_ca_message, void *arg)
211{
212 return -EOPNOTSUPP;
213}
214
215
216static int ca_get_slot_info(struct dst_state *state, struct ca_slot_info *p_ca_slot_info, void *arg)
217{
218 int i;
219 static u8 slot_command[8] = {0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
220
221 u8 *slot_info = state->rxbuffer;
222
223 put_checksum(&slot_command[0], 7);
224 if ((dst_put_ci(state, slot_command, sizeof (slot_command), slot_info, GET_REPLY)) < 0) {
225 dprintk("%s: -->dst_put_ci FAILED !\n", __FUNCTION__);
226 return -1;
227 }
228 if (verbose > 1)
229 dprintk("%s: -->dst_put_ci SUCCESS !\n", __FUNCTION__);
230
231 /* Will implement the rest soon */
232
233 if (verbose > 1) {
234 dprintk("%s: Slot info = [%d]\n", __FUNCTION__, slot_info[3]);
235 dprintk("===================================\n");
236 for (i = 0; i < 8; i++)
237 dprintk(" %d", slot_info[i]);
238 dprintk("\n");
239 }
240
241 if (slot_info[4] & 0x80) {
242 p_ca_slot_info->flags = CA_CI_MODULE_PRESENT;
243 p_ca_slot_info->num = 1;
244 p_ca_slot_info->type = CA_CI;
245 }
246 else if (slot_info[4] & 0x40) {
247 p_ca_slot_info->flags = CA_CI_MODULE_READY;
248 p_ca_slot_info->num = 1;
249 p_ca_slot_info->type = CA_CI;
250 }
251 else {
252 p_ca_slot_info->flags = 0;
253 }
254
255 if (copy_to_user((struct ca_slot_info *)arg, p_ca_slot_info, sizeof (struct ca_slot_info))) {
256 return -EFAULT;
257 }
258
259 return 0;
260}
261
262
263
264
265static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message, void *arg)
266{
267 u8 i = 0;
268 u32 command = 0;
269
270 if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg)))
271 return -EFAULT;
272
273
274 if (p_ca_message->msg) {
275 if (verbose > 3)
276 dprintk("Message = [%02x %02x %02x]\n", p_ca_message->msg[0], p_ca_message->msg[1], p_ca_message->msg[2]);
277
278 for (i = 0; i < 3; i++) {
279 command = command | p_ca_message->msg[i];
280 if (i < 2)
281 command = command << 8;
282 }
283 if (verbose > 3)
284 dprintk("%s:Command=[0x%x]\n", __FUNCTION__, command);
285
286 switch (command) {
287 case CA_APP_INFO:
288 memcpy(p_ca_message->msg, state->messages, 128);
289 if (copy_to_user((void *)arg, p_ca_message, sizeof (struct ca_msg)) )
290 return -EFAULT;
291 break;
292 }
293 }
294
295 return 0;
296}
297
298static int handle_en50221_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
299{
300 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
301 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
302 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
303 }
304 else {
305 hw_buffer->msg[2] = 0x03;
306 hw_buffer->msg[3] = 0x00;
307 }
308 return 0;
309}
310
311static int debug_8820_buffer(struct ca_msg *hw_buffer)
312{
313 unsigned int i;
314
315 dprintk("%s:Debug=[", __FUNCTION__);
316 for (i = 0; i < (hw_buffer->msg[0] + 1); i++)
317 dprintk(" %02x", hw_buffer->msg[i]);
318 dprintk("]\n");
319
320 return 0;
321}
322
323static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 reply)
324{
325 if ((dst_put_ci(state, hw_buffer->msg, (hw_buffer->length + 1), hw_buffer->msg, reply)) < 0) {
326 dprintk("%s: DST-CI Command failed.\n", __FUNCTION__);
327 dprintk("%s: Resetting DST.\n", __FUNCTION__);
328 rdc_reset_state(state);
329 return -1;
330 }
331 if (verbose > 2)
332 dprintk("%s: DST-CI Command succes.\n", __FUNCTION__);
333
334 return 0;
335}
336
337
338static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
339{
340 u32 hw_offset, buf_offset, i, k;
341 u32 program_info_length = 0, es_info_length = 0, length = 0, words = 0;
342 u8 found_prog_ca_desc = 0, found_stream_ca_desc = 0, error_condition = 0, hw_buffer_length = 0;
343
344 if (verbose > 3)
345 dprintk("%s, p_ca_message length %d (0x%x)\n", __FUNCTION__,p_ca_message->length,p_ca_message->length );
346
347 handle_en50221_tag(state, p_ca_message, hw_buffer); /* EN50221 tag */
348
349 /* Handle the length field (variable) */
350 if (!(p_ca_message->msg[3] & 0x80)) { /* Length = 1 */
351 length = p_ca_message->msg[3] & 0x7f;
352 words = 0; /* domi's suggestion */
353 }
354 else { /* Length = words */
355 words = p_ca_message->msg[3] & 0x7f;
356 for (i = 0; i < words; i++) {
357 length = length << 8;
358 length = length | p_ca_message->msg[4 + i];
359 }
360 }
361 if (verbose > 4) {
362 dprintk("%s:Length=[%d (0x%x)], Words=[%d]\n", __FUNCTION__, length,length, words);
363
364 /* Debug Input string */
365 for (i = 0; i < length; i++)
366 dprintk(" %02x", p_ca_message->msg[i]);
367 dprintk("]\n");
368 }
369
370 hw_offset = 7;
371 buf_offset = words + 4;
372
373 /* Program Header */
374 if (verbose > 4)
375 dprintk("\n%s:Program Header=[", __FUNCTION__);
376 for (i = 0; i < 6; i++) {
377 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
378 if (verbose > 4)
379 dprintk(" %02x", p_ca_message->msg[buf_offset]);
380 hw_offset++, buf_offset++, hw_buffer_length++;
381 }
382 if (verbose > 4)
383 dprintk("]\n");
384
385 program_info_length = 0;
386 program_info_length = (((program_info_length | p_ca_message->msg[words + 8]) & 0x0f) << 8) | p_ca_message->msg[words + 9];
387 if (verbose > 4)
388 dprintk("%s:Program info Length=[%d][%02x], hw_offset=[%d], buf_offset=[%d] \n",
389 __FUNCTION__, program_info_length, program_info_length, hw_offset, buf_offset);
390
391 if (program_info_length && (program_info_length < 256)) { /* If program_info_length */
392 hw_buffer->msg[11] = hw_buffer->msg[11] & 0x0f; /* req only 4 bits */
393 hw_buffer->msg[12] = hw_buffer->msg[12] + 1; /* increment! ASIC bug! */
394
395 if (p_ca_message->msg[buf_offset + 1] == 0x09) { /* Check CA descriptor */
396 found_prog_ca_desc = 1;
397 if (verbose > 4)
398 dprintk("%s: Found CA descriptor @ Program level\n", __FUNCTION__);
399 }
400
401 if (found_prog_ca_desc) { /* Command only if CA descriptor */
402 hw_buffer->msg[13] = p_ca_message->msg[buf_offset]; /* CA PMT command ID */
403 hw_offset++, buf_offset++, hw_buffer_length++;
404 }
405
406 /* Program descriptors */
407 if (verbose > 4) {
408 dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);
409 dprintk("%s:Program descriptors=[", __FUNCTION__);
410 }
411 while (program_info_length && !error_condition) { /* Copy prog descriptors */
412 if (program_info_length > p_ca_message->length) { /* Error situation */
413 dprintk ("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d]\n",
414 __FUNCTION__, __LINE__, program_info_length);
415 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
416 error_condition = 1;
417 break;
418 }
419
420 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
421 dprintk(" %02x", p_ca_message->msg[buf_offset]);
422 hw_offset++, buf_offset++, hw_buffer_length++, program_info_length--;
423 }
424 if (verbose > 4) {
425 dprintk("]\n");
426 dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);
427 }
428 if (found_prog_ca_desc) {
429 if (!reply) {
430 hw_buffer->msg[13] = 0x01; /* OK descrambling */
431 if (verbose > 1)
432 dprintk("CA PMT Command = OK Descrambling\n");
433 }
434 else {
435 hw_buffer->msg[13] = 0x02; /* Ok MMI */
436 if (verbose > 1)
437 dprintk("CA PMT Command = Ok MMI\n");
438 }
439 if (query) {
440 hw_buffer->msg[13] = 0x03; /* Query */
441 if (verbose > 1)
442 dprintk("CA PMT Command = CA PMT query\n");
443 }
444 }
445 }
446 else {
447 hw_buffer->msg[11] = hw_buffer->msg[11] & 0xf0; /* Don't write to ASIC */
448 hw_buffer->msg[12] = hw_buffer->msg[12] = 0x00;
449 }
450 if (verbose > 4)
451 dprintk("%s:**********>p_ca_message->length=[%d], buf_offset=[%d], hw_offset=[%d]\n",
452 __FUNCTION__, p_ca_message->length, buf_offset, hw_offset);
453
454 while ((buf_offset < p_ca_message->length) && !error_condition) {
455 /* Bail out in case of an indefinite loop */
456 if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
457 dprintk("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d], buf_offset=[%d]\n",
458 __FUNCTION__, __LINE__, program_info_length, buf_offset);
459
460 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
461 error_condition = 1;
462 break;
463 }
464
465 /* Stream Header */
466
467 for (k = 0; k < 5; k++) {
468 hw_buffer->msg[hw_offset + k] = p_ca_message->msg[buf_offset + k];
469 }
470
471 es_info_length = 0;
472 es_info_length = (es_info_length | (p_ca_message->msg[buf_offset + 3] & 0x0f)) << 8 | p_ca_message->msg[buf_offset + 4];
473
474 if (verbose > 4) {
475 dprintk("\n%s:----->Stream header=[%02x %02x %02x %02x %02x]\n", __FUNCTION__,
476 p_ca_message->msg[buf_offset + 0], p_ca_message->msg[buf_offset + 1],
477 p_ca_message->msg[buf_offset + 2], p_ca_message->msg[buf_offset + 3],
478 p_ca_message->msg[buf_offset + 4]);
479
480 dprintk("%s:----->Stream type=[%02x], es length=[%d (0x%x)], Chars=[%02x] [%02x], buf_offset=[%d]\n", __FUNCTION__,
481 p_ca_message->msg[buf_offset + 0], es_info_length, es_info_length,
482 p_ca_message->msg[buf_offset + 3], p_ca_message->msg[buf_offset + 4], buf_offset);
483 }
484
485 hw_buffer->msg[hw_offset + 3] &= 0x0f; /* req only 4 bits */
486
487 if (found_prog_ca_desc) {
488 hw_buffer->msg[hw_offset + 3] = 0x00;
489 hw_buffer->msg[hw_offset + 4] = 0x00;
490 }
491
492 hw_offset += 5, buf_offset += 5, hw_buffer_length += 5;
493
494 /* Check for CA descriptor */
495 if (p_ca_message->msg[buf_offset + 1] == 0x09) {
496 if (verbose > 4)
497 dprintk("%s:Found CA descriptor @ Stream level\n", __FUNCTION__);
498 found_stream_ca_desc = 1;
499 }
500
501 /* ES descriptors */
502
503 if (es_info_length && !error_condition && !found_prog_ca_desc && found_stream_ca_desc) {
504// if (!ca_pmt_done) {
505 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; /* CA PMT cmd(es) */
506 if (verbose > 4)
507 printk("%s:----->CA PMT Command ID=[%02x]\n", __FUNCTION__, p_ca_message->msg[buf_offset]);
508// hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--, ca_pmt_done = 1;
509 hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
510// }
511 if (verbose > 4)
512 dprintk("%s:----->ES descriptors=[", __FUNCTION__);
513
514 while (es_info_length && !error_condition) { /* ES descriptors */
515 if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
516 if (verbose > 4) {
517 dprintk("%s:\"WARNING\" ES Length error, line=[%d], es_info_length=[%d], buf_offset=[%d]\n",
518 __FUNCTION__, __LINE__, es_info_length, buf_offset);
519
520 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
521 }
522 error_condition = 1;
523 break;
524 }
525
526 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
527 if (verbose > 3)
528 dprintk("%02x ", hw_buffer->msg[hw_offset]);
529 hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
530 }
531 found_stream_ca_desc = 0; /* unset for new streams */
532 dprintk("]\n");
533 }
534 }
535
536 /* MCU Magic words */
537
538 hw_buffer_length += 7;
539 hw_buffer->msg[0] = hw_buffer_length;
540 hw_buffer->msg[1] = 64;
541 hw_buffer->msg[4] = 3;
542 hw_buffer->msg[5] = hw_buffer->msg[0] - 7;
543 hw_buffer->msg[6] = 0;
544
545
546 /* Fix length */
547 hw_buffer->length = hw_buffer->msg[0];
548
549 put_checksum(&hw_buffer->msg[0], hw_buffer->msg[0]);
550 /* Do the actual write */
551 if (verbose > 4) {
552 dprintk("%s:======================DEBUGGING================================\n", __FUNCTION__);
553 dprintk("%s: Actual Length=[%d]\n", __FUNCTION__, hw_buffer_length);
554 }
555 /* Only for debugging! */
556 if (verbose > 2)
557 debug_8820_buffer(hw_buffer);
558 if (verbose > 3)
559 dprintk("%s: Reply = [%d]\n", __FUNCTION__, reply);
560 write_to_8820(state, hw_buffer, reply);
561
562 return 0;
563}
564
565/* Board supports CA PMT reply ? */
566static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
567{
568 int ca_pmt_reply_test = 0;
569
570 /* Do test board */
571 /* Not there yet but soon */
572
573
574 /* CA PMT Reply capable */
575 if (ca_pmt_reply_test) {
576 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 1, GET_REPLY)) < 0) {
577 dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__);
578 return -1;
579 }
580
581 /* Process CA PMT Reply */
582 /* will implement soon */
583 dprintk("%s: Not there yet\n", __FUNCTION__);
584 }
585 /* CA PMT Reply not capable */
586 if (!ca_pmt_reply_test) {
587 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, NO_REPLY)) < 0) {
588 dprintk("%s: ca_set_pmt.. failed !\n", __FUNCTION__);
589 return -1;
590 }
591 if (verbose > 3)
592 dprintk("%s: ca_set_pmt.. success !\n", __FUNCTION__);
593 /* put a dummy message */
594
595 }
596 return 0;
597}
598
599static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, void *arg)
600{
601 int i = 0;
602 unsigned int ca_message_header_len;
603
604 u32 command = 0;
605 struct ca_msg *hw_buffer;
606
607 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
608 printk("%s: Memory allocation failure\n", __FUNCTION__);
609 return -ENOMEM;
610 }
611 if (verbose > 3)
612 dprintk("%s\n", __FUNCTION__);
613
614 if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg)))
615 return -EFAULT;
616
617 if (p_ca_message->msg) {
618 ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */
619 /* EN50221 tag */
620 command = 0;
621
622 for (i = 0; i < 3; i++) {
623 command = command | p_ca_message->msg[i];
624 if (i < 2)
625 command = command << 8;
626 }
627 if (verbose > 3)
628 dprintk("%s:Command=[0x%x]\n", __FUNCTION__, command);
629
630 switch (command) {
631 case CA_PMT:
632 if (verbose > 3)
633 dprintk("Command = SEND_CA_PMT\n");
634 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) {
635 dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__);
636 return -1;
637 }
638 if (verbose > 3)
639 dprintk("%s: -->CA_PMT Success !\n", __FUNCTION__);
640// retval = dummy_set_pmt(state, p_ca_message, hw_buffer, 0, 0);
641
642 break;
643
644 case CA_PMT_REPLY:
645 if (verbose > 3)
646 dprintk("Command = CA_PMT_REPLY\n");
647 /* Have to handle the 2 basic types of cards here */
648 if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) {
649 dprintk("%s: -->CA_PMT_REPLY Failed !\n", __FUNCTION__);
650 return -1;
651 }
652 if (verbose > 3)
653 dprintk("%s: -->CA_PMT_REPLY Success !\n", __FUNCTION__);
654
655 /* Certain boards do behave different ? */
656// retval = ca_set_pmt(state, p_ca_message, hw_buffer, 1, 1);
657
658 case CA_APP_INFO_ENQUIRY: // only for debugging
659 if (verbose > 3)
660 dprintk("%s: Getting Cam Application information\n", __FUNCTION__);
661
662 if ((ca_get_app_info(state)) < 0) {
663 dprintk("%s: -->CA_APP_INFO_ENQUIRY Failed !\n", __FUNCTION__);
664 return -1;
665 }
666 if (verbose > 3)
667 printk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__);
668
669 break;
670 }
671 }
672 return 0;
673}
674
675static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg)
676{
677 struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
678 struct dst_state* state = (struct dst_state*) dvbdev->priv;
679 struct ca_slot_info *p_ca_slot_info;
680 struct ca_caps *p_ca_caps;
681 struct ca_msg *p_ca_message;
682
683 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
684 printk("%s: Memory allocation failure\n", __FUNCTION__);
685 return -ENOMEM;
686 }
687
688 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
689 printk("%s: Memory allocation failure\n", __FUNCTION__);
690 return -ENOMEM;
691 }
692
693 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
694 printk("%s: Memory allocation failure\n", __FUNCTION__);
695 return -ENOMEM;
696 }
697
698 /* We have now only the standard ioctl's, the driver is upposed to handle internals. */
699 switch (cmd) {
700 case CA_SEND_MSG:
701 if (verbose > 1)
702 dprintk("%s: Sending message\n", __FUNCTION__);
703 if ((ca_send_message(state, p_ca_message, arg)) < 0) {
704 dprintk("%s: -->CA_SEND_MSG Failed !\n", __FUNCTION__);
705 return -1;
706 }
707
708 break;
709
710 case CA_GET_MSG:
711 if (verbose > 1)
712 dprintk("%s: Getting message\n", __FUNCTION__);
713 if ((ca_get_message(state, p_ca_message, arg)) < 0) {
714 dprintk("%s: -->CA_GET_MSG Failed !\n", __FUNCTION__);
715 return -1;
716 }
717 if (verbose > 1)
718 dprintk("%s: -->CA_GET_MSG Success !\n", __FUNCTION__);
719
720 break;
721
722 case CA_RESET:
723 if (verbose > 1)
724 dprintk("%s: Resetting DST\n", __FUNCTION__);
725 dst_error_bailout(state);
726 msleep(4000);
727
728 break;
729
730 case CA_GET_SLOT_INFO:
731 if (verbose > 1)
732 dprintk("%s: Getting Slot info\n", __FUNCTION__);
733 if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
734 dprintk("%s: -->CA_GET_SLOT_INFO Failed !\n", __FUNCTION__);
735 return -1;
736 }
737 if (verbose > 1)
738 dprintk("%s: -->CA_GET_SLOT_INFO Success !\n", __FUNCTION__);
739
740 break;
741
742 case CA_GET_CAP:
743 if (verbose > 1)
744 dprintk("%s: Getting Slot capabilities\n", __FUNCTION__);
745 if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
746 dprintk("%s: -->CA_GET_CAP Failed !\n", __FUNCTION__);
747 return -1;
748 }
749 if (verbose > 1)
750 dprintk("%s: -->CA_GET_CAP Success !\n", __FUNCTION__);
751
752 break;
753
754 case CA_GET_DESCR_INFO:
755 if (verbose > 1)
756 dprintk("%s: Getting descrambler description\n", __FUNCTION__);
757 if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
758 dprintk("%s: -->CA_GET_DESCR_INFO Failed !\n", __FUNCTION__);
759 return -1;
760 }
761 if (verbose > 1)
762 dprintk("%s: -->CA_GET_DESCR_INFO Success !\n", __FUNCTION__);
763
764 break;
765
766 case CA_SET_DESCR:
767 if (verbose > 1)
768 dprintk("%s: Setting descrambler\n", __FUNCTION__);
769 if ((ca_set_slot_descr()) < 0) {
770 dprintk("%s: -->CA_SET_DESCR Failed !\n", __FUNCTION__);
771 return -1;
772 }
773 if (verbose > 1)
774 dprintk("%s: -->CA_SET_DESCR Success !\n", __FUNCTION__);
775
776 break;
777
778 case CA_SET_PID:
779 if (verbose > 1)
780 dprintk("%s: Setting PID\n", __FUNCTION__);
781 if ((ca_set_pid()) < 0) {
782 dprintk("%s: -->CA_SET_PID Failed !\n", __FUNCTION__);
783 return -1;
784 }
785 if (verbose > 1)
786 dprintk("%s: -->CA_SET_PID Success !\n", __FUNCTION__);
787
788 default:
789 return -EOPNOTSUPP;
790 };
791
792 return 0;
793}
794
795static int dst_ca_open(struct inode *inode, struct file *file)
796{
797 if (verbose > 4)
798 dprintk("%s:Device opened [%p]\n", __FUNCTION__, file);
799 try_module_get(THIS_MODULE);
800
801 return 0;
802}
803
804static int dst_ca_release(struct inode *inode, struct file *file)
805{
806 if (verbose > 4)
807 dprintk("%s:Device closed.\n", __FUNCTION__);
808 module_put(THIS_MODULE);
809
810 return 0;
811}
812
813static int dst_ca_read(struct file *file, char __user * buffer, size_t length, loff_t * offset)
814{
815 int bytes_read = 0;
816
817 if (verbose > 4)
818 dprintk("%s:Device read.\n", __FUNCTION__);
819
820 return bytes_read;
821}
822
823static int dst_ca_write(struct file *file, const char __user * buffer, size_t length, loff_t * offset)
824{
825 if (verbose > 4)
826 dprintk("%s:Device write.\n", __FUNCTION__);
827
828 return 0;
829}
830
831static struct file_operations dst_ca_fops = {
832 .owner = THIS_MODULE,
833 .ioctl = (void *)dst_ca_ioctl,
834 .open = dst_ca_open,
835 .release = dst_ca_release,
836 .read = dst_ca_read,
837 .write = dst_ca_write
838};
839
840static struct dvb_device dvbdev_ca = {
841 .priv = NULL,
842 .users = 1,
843 .readers = 1,
844 .writers = 1,
845 .fops = &dst_ca_fops
846};
847
848int dst_ca_attach(struct dst_state *dst, struct dvb_adapter *dvb_adapter)
849{
850 struct dvb_device *dvbdev;
851 if (verbose > 4)
852 dprintk("%s:registering DST-CA device\n", __FUNCTION__);
853 dvb_register_device(dvb_adapter, &dvbdev, &dvbdev_ca, dst, DVB_DEVICE_CA);
854 return 0;
855}
856
857EXPORT_SYMBOL(dst_ca_attach);
858
859MODULE_DESCRIPTION("DST DVB-S/T/C Combo CA driver");
860MODULE_AUTHOR("Manu Abraham");
861MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/bt8xx/dst_ca.h b/drivers/media/dvb/bt8xx/dst_ca.h
new file mode 100644
index 000000000000..59cd0ddd6d8e
--- /dev/null
+++ b/drivers/media/dvb/bt8xx/dst_ca.h
@@ -0,0 +1,58 @@
1/*
2 CA-driver for TwinHan DST Frontend/Card
3
4 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef _DST_CA_H_
22#define _DST_CA_H_
23
24#define RETRIES 5
25
26
27#define CA_APP_INFO_ENQUIRY 0x9f8020
28#define CA_APP_INFO 0x9f8021
29#define CA_ENTER_MENU 0x9f8022
30#define CA_INFO_ENQUIRY 0x9f8030
31#define CA_INFO 0x9f8031
32#define CA_PMT 0x9f8032
33#define CA_PMT_REPLY 0x9f8033
34
35#define CA_CLOSE_MMI 0x9f8800
36#define CA_DISPLAY_CONTROL 0x9f8801
37#define CA_DISPLAY_REPLY 0x9f8802
38#define CA_TEXT_LAST 0x9f8803
39#define CA_TEXT_MORE 0x9f8804
40#define CA_KEYPAD_CONTROL 0x9f8805
41#define CA_KEYPRESS 0x9f8806
42
43#define CA_ENQUIRY 0x9f8807
44#define CA_ANSWER 0x9f8808
45#define CA_MENU_LAST 0x9f8809
46#define CA_MENU_MORE 0x9f880a
47#define CA_MENU_ANSWER 0x9f880b
48#define CA_LIST_LAST 0x9f880c
49#define CA_LIST_MORE 0x9f880d
50
51
52struct dst_ca_private {
53 struct dst_state *dst;
54 struct dvb_device *dvbdev;
55};
56
57
58#endif
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
new file mode 100644
index 000000000000..0b3da29245fb
--- /dev/null
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -0,0 +1,153 @@
1/*
2 Frontend-driver for TwinHan DST Frontend
3
4 Copyright (C) 2003 Jamie Honan
5 Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#ifndef DST_COMMON_H
23#define DST_COMMON_H
24
25#include <linux/dvb/frontend.h>
26#include <linux/device.h>
27#include "bt878.h"
28
29#include "dst_ca.h"
30
31
32#define NO_DELAY 0
33#define LONG_DELAY 1
34#define DEVICE_INIT 2
35
36#define DELAY 1
37
38#define DST_TYPE_IS_SAT 0
39#define DST_TYPE_IS_TERR 1
40#define DST_TYPE_IS_CABLE 2
41#define DST_TYPE_IS_ATSC 3
42
43#define DST_TYPE_HAS_NEWTUNE 1
44#define DST_TYPE_HAS_TS204 2
45#define DST_TYPE_HAS_SYMDIV 4
46#define DST_TYPE_HAS_FW_1 8
47#define DST_TYPE_HAS_FW_2 16
48#define DST_TYPE_HAS_FW_3 32
49#define DST_TYPE_HAS_FW_BUILD 64
50
51/* Card capability list */
52
53#define DST_TYPE_HAS_MAC 1
54#define DST_TYPE_HAS_DISEQC3 2
55#define DST_TYPE_HAS_DISEQC4 4
56#define DST_TYPE_HAS_DISEQC5 8
57#define DST_TYPE_HAS_MOTO 16
58#define DST_TYPE_HAS_CA 32
59#define DST_TYPE_HAS_ANALOG 64 /* Analog inputs */
60#define DST_TYPE_HAS_SESSION 128
61
62
63#define RDC_8820_PIO_0_DISABLE 0
64#define RDC_8820_PIO_0_ENABLE 1
65#define RDC_8820_INT 2
66#define RDC_8820_RESET 4
67
68/* DST Communication */
69#define GET_REPLY 1
70#define NO_REPLY 0
71
72#define GET_ACK 1
73#define FIXED_COMM 8
74
75#define ACK 0xff
76
77struct dst_state {
78
79 struct i2c_adapter* i2c;
80
81 struct bt878* bt;
82
83 struct dvb_frontend_ops ops;
84
85 /* configuration settings */
86 const struct dst_config* config;
87
88 struct dvb_frontend frontend;
89
90 /* private ASIC data */
91 u8 tx_tuna[10];
92 u8 rx_tuna[10];
93 u8 rxbuffer[10];
94 u8 diseq_flags;
95 u8 dst_type;
96 u32 type_flags;
97 u32 frequency; /* intermediate frequency in kHz for QPSK */
98 fe_spectral_inversion_t inversion;
99 u32 symbol_rate; /* symbol rate in Symbols per second */
100 fe_code_rate_t fec;
101 fe_sec_voltage_t voltage;
102 fe_sec_tone_mode_t tone;
103 u32 decode_freq;
104 u8 decode_lock;
105 u16 decode_strength;
106 u16 decode_snr;
107 unsigned long cur_jiff;
108 u8 k22;
109 fe_bandwidth_t bandwidth;
110 u32 dst_hw_cap;
111 u8 dst_fw_version;
112 fe_sec_mini_cmd_t minicmd;
113 u8 messages[256];
114};
115
116struct dst_types {
117 char *device_id;
118 int offset;
119 u8 dst_type;
120 u32 type_flags;
121 u32 dst_feature;
122};
123
124
125
126struct dst_config
127{
128 /* the ASIC i2c address */
129 u8 demod_address;
130};
131
132
133int rdc_reset_state(struct dst_state *state);
134int rdc_8820_reset(struct dst_state *state);
135
136int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode);
137int dst_pio_enable(struct dst_state *state);
138int dst_pio_disable(struct dst_state *state);
139int dst_error_recovery(struct dst_state* state);
140int dst_error_bailout(struct dst_state *state);
141int dst_comm_init(struct dst_state* state);
142
143int write_dst(struct dst_state *state, u8 * data, u8 len);
144int read_dst(struct dst_state *state, u8 * ret, u8 len);
145u8 dst_check_sum(u8 * buf, u32 len);
146struct dst_state* dst_attach(struct dst_state* state, struct dvb_adapter *dvb_adapter);
147int dst_ca_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter);
148int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay);
149
150int dst_command(struct dst_state* state, u8 * data, u8 len);
151
152
153#endif // DST_COMMON_H
diff --git a/drivers/media/dvb/bt8xx/dst_priv.h b/drivers/media/dvb/bt8xx/dst_priv.h
index 80488aa628b4..3974a4c6ebe7 100644
--- a/drivers/media/dvb/bt8xx/dst_priv.h
+++ b/drivers/media/dvb/bt8xx/dst_priv.h
@@ -33,4 +33,3 @@ union dst_gpio_packet {
33struct bt878; 33struct bt878;
34 34
35int bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *mp); 35int bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *mp);
36
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index b735397f59aa..6f857c6091f3 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -142,7 +142,7 @@ static int thomson_dtt7579_demod_init(struct dvb_frontend* fe)
142 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); 142 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
143 143
144 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg)); 144 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
145 mt352_write(fe, mt352_gpp_ctl_cfg, sizeof(mt352_gpp_ctl_cfg)); 145 mt352_write(fe, mt352_gpp_ctl_cfg, sizeof(mt352_gpp_ctl_cfg));
146 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); 146 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
147 147
148 return 0; 148 return 0;
@@ -161,7 +161,7 @@ static int thomson_dtt7579_pll_set(struct dvb_frontend* fe, struct dvb_frontend_
161 else if (params->frequency < 771000000) cp = 0xbc; 161 else if (params->frequency < 771000000) cp = 0xbc;
162 else cp = 0xf4; 162 else cp = 0xf4;
163 163
164 if (params->frequency == 0) bs = 0x03; 164 if (params->frequency == 0) bs = 0x03;
165 else if (params->frequency < 443250000) bs = 0x02; 165 else if (params->frequency < 443250000) bs = 0x02;
166 else bs = 0x08; 166 else bs = 0x08;
167 167
@@ -190,44 +190,44 @@ static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_paramete
190 190
191 191
192 u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000, 192 u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000,
193 1576000,1718000,1856000,2036000,2150000}; 193 1576000,1718000,1856000,2036000,2150000};
194 u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000, 194 u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000,
195 0x00102000,0x00104000,0x00108000,0x00110000, 195 0x00102000,0x00104000,0x00108000,0x00110000,
196 0x00120000,0x00140000}; 196 0x00120000,0x00140000};
197 197
198#define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */ 198#define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */
199 printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq); 199 printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq);
200 200
201 /* This is really the bit driving the tuner chip cx24108 */ 201 /* This is really the bit driving the tuner chip cx24108 */
202 202
203 if(freq<950000) freq=950000; /* kHz */ 203 if(freq<950000) freq=950000; /* kHz */
204 if(freq>2150000) freq=2150000; /* satellite IF is 950..2150MHz */ 204 if(freq>2150000) freq=2150000; /* satellite IF is 950..2150MHz */
205 205
206 /* decide which VCO to use for the input frequency */ 206 /* decide which VCO to use for the input frequency */
207 for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++); 207 for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++);
208 printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq); 208 printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq);
209 band=bandsel[i]; 209 band=bandsel[i];
210 /* the gain values must be set by SetSymbolrate */ 210 /* the gain values must be set by SetSymbolrate */
211 /* compute the pll divider needed, from Conexant data sheet, 211 /* compute the pll divider needed, from Conexant data sheet,
212 resolved for (n*32+a), remember f(vco) is f(receive) *2 or *4, 212 resolved for (n*32+a), remember f(vco) is f(receive) *2 or *4,
213 depending on the divider bit. It is set to /4 on the 2 lowest 213 depending on the divider bit. It is set to /4 on the 2 lowest
214 bands */ 214 bands */
215 n=((i<=2?2:1)*freq*10L)/(XTAL/100); 215 n=((i<=2?2:1)*freq*10L)/(XTAL/100);
216 a=n%32; n/=32; if(a==0) n--; 216 a=n%32; n/=32; if(a==0) n--;
217 pump=(freq<(osci[i-1]+osci[i])/2); 217 pump=(freq<(osci[i-1]+osci[i])/2);
218 pll=0xf8000000| 218 pll=0xf8000000|
219 ((pump?1:2)<<(14+11))| 219 ((pump?1:2)<<(14+11))|
220 ((n&0x1ff)<<(5+11))| 220 ((n&0x1ff)<<(5+11))|
221 ((a&0x1f)<<11); 221 ((a&0x1f)<<11);
222 /* everything is shifted left 11 bits to left-align the bits in the 222 /* everything is shifted left 11 bits to left-align the bits in the
223 32bit word. Output to the tuner goes MSB-aligned, after all */ 223 32bit word. Output to the tuner goes MSB-aligned, after all */
224 printk("cx24108 debug: pump=%d, n=%d, a=%d\n",pump,n,a); 224 printk("cx24108 debug: pump=%d, n=%d, a=%d\n",pump,n,a);
225 cx24110_pll_write(fe,band); 225 cx24110_pll_write(fe,band);
226 /* set vga and vca to their widest-band settings, as a precaution. 226 /* set vga and vca to their widest-band settings, as a precaution.
227 SetSymbolrate might not be called to set this up */ 227 SetSymbolrate might not be called to set this up */
228 cx24110_pll_write(fe,0x500c0000); 228 cx24110_pll_write(fe,0x500c0000);
229 cx24110_pll_write(fe,0x83f1f800); 229 cx24110_pll_write(fe,0x83f1f800);
230 cx24110_pll_write(fe,pll); 230 cx24110_pll_write(fe,pll);
231/* writereg(client,0x56,0x7f);*/ 231/* writereg(client,0x56,0x7f);*/
232 232
233 return 0; 233 return 0;
@@ -299,7 +299,7 @@ static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
299 static u8 mt352_reset [] = { 0x50, 0x80 }; 299 static u8 mt352_reset [] = { 0x50, 0x80 };
300 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; 300 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
301 static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF, 301 static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
302 0x00, 0xFF, 0x00, 0x40, 0x40 }; 302 0x00, 0xFF, 0x00, 0x40, 0x40 };
303 static u8 mt352_av771_extra[] = { 0xB5, 0x7A }; 303 static u8 mt352_av771_extra[] = { 0xB5, 0x7A };
304 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; 304 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
305 305
@@ -463,6 +463,9 @@ static struct nxt6000_config vp3021_alps_tded4_config = {
463 463
464static void frontend_init(struct dvb_bt8xx_card *card, u32 type) 464static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
465{ 465{
466 int ret;
467 struct dst_state* state = NULL;
468
466 switch(type) { 469 switch(type) {
467#ifdef BTTV_DVICO_DVBT_LITE 470#ifdef BTTV_DVICO_DVBT_LITE
468 case BTTV_DVICO_DVBT_LITE: 471 case BTTV_DVICO_DVBT_LITE:
@@ -503,7 +506,25 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
503 break; 506 break;
504 507
505 case BTTV_TWINHAN_DST: 508 case BTTV_TWINHAN_DST:
506 card->fe = dst_attach(&dst_config, card->i2c_adapter, card->bt); 509 /* DST is not a frontend driver !!! */
510 state = (struct dst_state *) kmalloc(sizeof (struct dst_state), GFP_KERNEL);
511 /* Setup the Card */
512 state->config = &dst_config;
513 state->i2c = card->i2c_adapter;
514 state->bt = card->bt;
515
516 /* DST is not a frontend, attaching the ASIC */
517 if ((dst_attach(state, &card->dvb_adapter)) == NULL) {
518 printk("%s: Could not find a Twinhan DST.\n", __FUNCTION__);
519 break;
520 }
521 card->fe = &state->frontend;
522
523 /* Attach other DST peripherals if any */
524 /* Conditional Access device */
525 if (state->dst_hw_cap & DST_TYPE_HAS_CA) {
526 ret = dst_ca_attach(state, &card->dvb_adapter);
527 }
507 if (card->fe != NULL) { 528 if (card->fe != NULL) {
508 break; 529 break;
509 } 530 }
@@ -531,7 +552,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
531 card->bt->dev->subsystem_vendor, 552 card->bt->dev->subsystem_vendor,
532 card->bt->dev->subsystem_device); 553 card->bt->dev->subsystem_device);
533 } else { 554 } else {
534 if (dvb_register_frontend(card->dvb_adapter, card->fe)) { 555 if (dvb_register_frontend(&card->dvb_adapter, card->fe)) {
535 printk("dvb-bt8xx: Frontend registration failed!\n"); 556 printk("dvb-bt8xx: Frontend registration failed!\n");
536 if (card->fe->ops->release) 557 if (card->fe->ops->release)
537 card->fe->ops->release(card->fe); 558 card->fe->ops->release(card->fe);
@@ -550,7 +571,7 @@ static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
550 return result; 571 return result;
551 572
552 } 573 }
553 card->dvb_adapter->priv = card; 574 card->dvb_adapter.priv = card;
554 575
555 card->bt->adapter = card->i2c_adapter; 576 card->bt->adapter = card->i2c_adapter;
556 577
@@ -568,7 +589,7 @@ static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
568 if ((result = dvb_dmx_init(&card->demux)) < 0) { 589 if ((result = dvb_dmx_init(&card->demux)) < 0) {
569 printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); 590 printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
570 591
571 dvb_unregister_adapter(card->dvb_adapter); 592 dvb_unregister_adapter(&card->dvb_adapter);
572 return result; 593 return result;
573 } 594 }
574 595
@@ -576,11 +597,11 @@ static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
576 card->dmxdev.demux = &card->demux.dmx; 597 card->dmxdev.demux = &card->demux.dmx;
577 card->dmxdev.capabilities = 0; 598 card->dmxdev.capabilities = 0;
578 599
579 if ((result = dvb_dmxdev_init(&card->dmxdev, card->dvb_adapter)) < 0) { 600 if ((result = dvb_dmxdev_init(&card->dmxdev, &card->dvb_adapter)) < 0) {
580 printk("dvb_bt8xx: dvb_dmxdev_init failed (errno = %d)\n", result); 601 printk("dvb_bt8xx: dvb_dmxdev_init failed (errno = %d)\n", result);
581 602
582 dvb_dmx_release(&card->demux); 603 dvb_dmx_release(&card->demux);
583 dvb_unregister_adapter(card->dvb_adapter); 604 dvb_unregister_adapter(&card->dvb_adapter);
584 return result; 605 return result;
585 } 606 }
586 607
@@ -591,7 +612,7 @@ static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
591 612
592 dvb_dmxdev_release(&card->dmxdev); 613 dvb_dmxdev_release(&card->dmxdev);
593 dvb_dmx_release(&card->demux); 614 dvb_dmx_release(&card->demux);
594 dvb_unregister_adapter(card->dvb_adapter); 615 dvb_unregister_adapter(&card->dvb_adapter);
595 return result; 616 return result;
596 } 617 }
597 618
@@ -603,7 +624,7 @@ static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
603 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); 624 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
604 dvb_dmxdev_release(&card->dmxdev); 625 dvb_dmxdev_release(&card->dmxdev);
605 dvb_dmx_release(&card->demux); 626 dvb_dmx_release(&card->demux);
606 dvb_unregister_adapter(card->dvb_adapter); 627 dvb_unregister_adapter(&card->dvb_adapter);
607 return result; 628 return result;
608 } 629 }
609 630
@@ -614,11 +635,11 @@ static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
614 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); 635 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
615 dvb_dmxdev_release(&card->dmxdev); 636 dvb_dmxdev_release(&card->dmxdev);
616 dvb_dmx_release(&card->demux); 637 dvb_dmx_release(&card->demux);
617 dvb_unregister_adapter(card->dvb_adapter); 638 dvb_unregister_adapter(&card->dvb_adapter);
618 return result; 639 return result;
619 } 640 }
620 641
621 dvb_net_init(card->dvb_adapter, &card->dvbnet, &card->demux.dmx); 642 dvb_net_init(&card->dvb_adapter, &card->dvbnet, &card->demux.dmx);
622 643
623 tasklet_init(&card->bt->tasklet, dvb_bt8xx_task, (unsigned long) card); 644 tasklet_init(&card->bt->tasklet, dvb_bt8xx_task, (unsigned long) card);
624 645
@@ -648,7 +669,7 @@ static int dvb_bt8xx_probe(struct device *dev)
648 case BTTV_PINNACLESAT: 669 case BTTV_PINNACLESAT:
649 card->gpio_mode = 0x0400c060; 670 card->gpio_mode = 0x0400c060;
650 /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR, 671 /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR,
651 BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */ 672 BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */
652 card->op_sync_orin = 0; 673 card->op_sync_orin = 0;
653 card->irq_err_ignore = 0; 674 card->irq_err_ignore = 0;
654 break; 675 break;
@@ -759,7 +780,7 @@ static int dvb_bt8xx_remove(struct device *dev)
759 dvb_dmxdev_release(&card->dmxdev); 780 dvb_dmxdev_release(&card->dmxdev);
760 dvb_dmx_release(&card->demux); 781 dvb_dmx_release(&card->demux);
761 if (card->fe) dvb_unregister_frontend(card->fe); 782 if (card->fe) dvb_unregister_frontend(card->fe);
762 dvb_unregister_adapter(card->dvb_adapter); 783 dvb_unregister_adapter(&card->dvb_adapter);
763 784
764 kfree(card); 785 kfree(card);
765 786
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.h b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
index 80ef189f930f..2923b3b0dd3c 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.h
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
@@ -31,7 +31,7 @@
31#include "bttv.h" 31#include "bttv.h"
32#include "mt352.h" 32#include "mt352.h"
33#include "sp887x.h" 33#include "sp887x.h"
34#include "dst.h" 34#include "dst_common.h"
35#include "nxt6000.h" 35#include "nxt6000.h"
36#include "cx24110.h" 36#include "cx24110.h"
37#include "or51211.h" 37#include "or51211.h"
@@ -40,7 +40,7 @@ struct dvb_bt8xx_card {
40 struct semaphore lock; 40 struct semaphore lock;
41 int nfeeds; 41 int nfeeds;
42 char card_name[32]; 42 char card_name[32];
43 struct dvb_adapter *dvb_adapter; 43 struct dvb_adapter dvb_adapter;
44 struct bt878 *bt; 44 struct bt878 *bt;
45 unsigned int bttv_nr; 45 unsigned int bttv_nr;
46 struct dvb_demux demux; 46 struct dvb_demux demux;
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 28d4d926de3e..96c57fde95a0 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -119,7 +119,7 @@ struct cinergyt2 {
119 struct dvb_demux demux; 119 struct dvb_demux demux;
120 struct usb_device *udev; 120 struct usb_device *udev;
121 struct semaphore sem; 121 struct semaphore sem;
122 struct dvb_adapter *adapter; 122 struct dvb_adapter adapter;
123 struct dvb_device *fedev; 123 struct dvb_device *fedev;
124 struct dmxdev dmxdev; 124 struct dmxdev dmxdev;
125 struct dvb_net dvbnet; 125 struct dvb_net dvbnet;
@@ -813,15 +813,15 @@ static int cinergyt2_probe (struct usb_interface *intf,
813 cinergyt2->dmxdev.demux = &cinergyt2->demux.dmx; 813 cinergyt2->dmxdev.demux = &cinergyt2->demux.dmx;
814 cinergyt2->dmxdev.capabilities = 0; 814 cinergyt2->dmxdev.capabilities = 0;
815 815
816 if ((err = dvb_dmxdev_init(&cinergyt2->dmxdev, cinergyt2->adapter)) < 0) { 816 if ((err = dvb_dmxdev_init(&cinergyt2->dmxdev, &cinergyt2->adapter)) < 0) {
817 dprintk(1, "dvb_dmxdev_init() failed (err = %d)\n", err); 817 dprintk(1, "dvb_dmxdev_init() failed (err = %d)\n", err);
818 goto bailout; 818 goto bailout;
819 } 819 }
820 820
821 if (dvb_net_init(cinergyt2->adapter, &cinergyt2->dvbnet, &cinergyt2->demux.dmx)) 821 if (dvb_net_init(&cinergyt2->adapter, &cinergyt2->dvbnet, &cinergyt2->demux.dmx))
822 dprintk(1, "dvb_net_init() failed!\n"); 822 dprintk(1, "dvb_net_init() failed!\n");
823 823
824 dvb_register_device(cinergyt2->adapter, &cinergyt2->fedev, 824 dvb_register_device(&cinergyt2->adapter, &cinergyt2->fedev,
825 &cinergyt2_fe_template, cinergyt2, 825 &cinergyt2_fe_template, cinergyt2,
826 DVB_DEVICE_FRONTEND); 826 DVB_DEVICE_FRONTEND);
827 827
@@ -848,7 +848,7 @@ static int cinergyt2_probe (struct usb_interface *intf,
848bailout: 848bailout:
849 dvb_dmxdev_release(&cinergyt2->dmxdev); 849 dvb_dmxdev_release(&cinergyt2->dmxdev);
850 dvb_dmx_release(&cinergyt2->demux); 850 dvb_dmx_release(&cinergyt2->demux);
851 dvb_unregister_adapter (cinergyt2->adapter); 851 dvb_unregister_adapter (&cinergyt2->adapter);
852 cinergyt2_free_stream_urbs (cinergyt2); 852 cinergyt2_free_stream_urbs (cinergyt2);
853 kfree(cinergyt2); 853 kfree(cinergyt2);
854 return -ENOMEM; 854 return -ENOMEM;
@@ -872,7 +872,7 @@ static void cinergyt2_disconnect (struct usb_interface *intf)
872 dvb_dmxdev_release(&cinergyt2->dmxdev); 872 dvb_dmxdev_release(&cinergyt2->dmxdev);
873 dvb_dmx_release(&cinergyt2->demux); 873 dvb_dmx_release(&cinergyt2->demux);
874 dvb_unregister_device(cinergyt2->fedev); 874 dvb_unregister_device(cinergyt2->fedev);
875 dvb_unregister_adapter(cinergyt2->adapter); 875 dvb_unregister_adapter(&cinergyt2->adapter);
876 876
877 cinergyt2_free_stream_urbs(cinergyt2); 877 cinergyt2_free_stream_urbs(cinergyt2);
878 up(&cinergyt2->sem); 878 up(&cinergyt2->sem);
diff --git a/drivers/media/dvb/dibusb/Kconfig b/drivers/media/dvb/dibusb/Kconfig
deleted file mode 100644
index 74dfc73ae5b0..000000000000
--- a/drivers/media/dvb/dibusb/Kconfig
+++ /dev/null
@@ -1,62 +0,0 @@
1config DVB_DIBUSB
2 tristate "DiBcom USB DVB-T devices (see help for a complete device list)"
3 depends on DVB_CORE && USB
4 select FW_LOADER
5 select DVB_DIB3000MB
6 select DVB_DIB3000MC
7 select DVB_MT352
8 help
9 Support for USB 1.1 and 2.0 DVB-T devices based on reference designs made by
10 DiBcom (http://www.dibcom.fr) and C&E.
11
12 Devices supported by this driver:
13
14 TwinhanDTV USB-Ter (VP7041)
15 TwinhanDTV Magic Box (VP7041e)
16 KWorld/JetWay/ADSTech V-Stream XPERT DTV - DVB-T USB1.1 and USB2.0
17 Hama DVB-T USB-Box
18 DiBcom reference devices (non-public)
19 Ultima Electronic/Artec T1 USB TVBOX
20 Compro Videomate DVB-U2000 - DVB-T USB
21 Grandtec DVB-T USB
22 Avermedia AverTV DVBT USB
23 Artec T1 USB1.1 and USB2.0 boxes
24 Yakumo/Typhoon DVB-T USB2.0
25 Hanftek UMT-010 USB2.0
26 Hauppauge WinTV NOVA-T USB2
27
28 The VP7041 seems to be identical to "CTS Portable" (Chinese
29 Television System).
30
31 These devices can be understood as budget ones, they "only" deliver
32 (a part of) the MPEG2 transport stream.
33
34 A firmware is needed to get the device working. See Documentation/dvb/README.dibusb
35 details.
36
37 Say Y if you own such a device and want to use it. You should build it as
38 a module.
39
40config DVB_DIBUSB_MISDESIGNED_DEVICES
41 bool "Enable support for some misdesigned (see help) devices, which identify with wrong IDs"
42 depends on DVB_DIBUSB
43 help
44 Somehow Artec/Ultima Electronic forgot to program the eeprom of some of their
45 USB1.1/USB2.0 devices.
46 So comes that they identify with the default Vendor and Product ID of the Cypress
47 CY7C64613 (AN2235) or Cypress FX2.
48
49 Affected device IDs:
50 0x0574:0x2235 (Artec T1 USB1.1, cold)
51 0x04b4:0x8613 (Artec T1 USB2.0, cold)
52 0x0574:0x1002 (Artec T1 USB2.0, warm)
53 0x0574:0x2131 (aged DiBcom USB1.1 test device)
54
55 Say Y if your device has one of the mentioned IDs.
56
57config DVB_DIBCOM_DEBUG
58 bool "Enable extended debug support for DiBcom USB device"
59 depends on DVB_DIBUSB
60 help
61 Say Y if you want to enable debuging. See modinfo dvb-dibusb for
62 debug levels.
diff --git a/drivers/media/dvb/dibusb/Makefile b/drivers/media/dvb/dibusb/Makefile
deleted file mode 100644
index e941c508624e..000000000000
--- a/drivers/media/dvb/dibusb/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
1dvb-dibusb-objs = dvb-dibusb-core.o \
2 dvb-dibusb-dvb.o \
3 dvb-dibusb-fe-i2c.o \
4 dvb-dibusb-firmware.o \
5 dvb-dibusb-remote.o \
6 dvb-dibusb-usb.o \
7 dvb-fe-dtt200u.o
8
9obj-$(CONFIG_DVB_DIBUSB) += dvb-dibusb.o
10
11EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/dibusb/dvb-dibusb-core.c b/drivers/media/dvb/dibusb/dvb-dibusb-core.c
deleted file mode 100644
index 26235f9247e4..000000000000
--- a/drivers/media/dvb/dibusb/dvb-dibusb-core.c
+++ /dev/null
@@ -1,558 +0,0 @@
1/*
2 * Driver for mobile USB Budget DVB-T devices based on reference
3 * design made by DiBcom (http://www.dibcom.fr/)
4 *
5 * dvb-dibusb-core.c
6 *
7 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
8 *
9 * based on GPL code from DiBcom, which has
10 * Copyright (C) 2004 Amaury Demol for DiBcom (ademol@dibcom.fr)
11 *
12 * Remote control code added by David Matthews (dm@prolingua.co.uk)
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation, version 2.
17 *
18 * Acknowledgements
19 *
20 * Amaury Demol (ademol@dibcom.fr) from DiBcom for providing specs and driver
21 * sources, on which this driver (and the dib3000mb/mc/p frontends) are based.
22 *
23 * see Documentation/dvb/README.dibusb for more information
24 */
25#include "dvb-dibusb.h"
26
27#include <linux/moduleparam.h>
28
29/* debug */
30int dvb_dibusb_debug;
31module_param_named(debug, dvb_dibusb_debug, int, 0644);
32
33#ifdef CONFIG_DVB_DIBCOM_DEBUG
34#define DBSTATUS ""
35#else
36#define DBSTATUS " (debugging is not enabled)"
37#endif
38MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=alotmore,8=ts,16=err,32=rc (|-able))." DBSTATUS);
39#undef DBSTATUS
40
41static int pid_parse;
42module_param(pid_parse, int, 0644);
43MODULE_PARM_DESC(pid_parse, "enable pid parsing (filtering) when running at USB2.0");
44
45static int rc_query_interval = 100;
46module_param(rc_query_interval, int, 0644);
47MODULE_PARM_DESC(rc_query_interval, "interval in msecs for remote control query (default: 100; min: 40)");
48
49static int rc_key_repeat_count = 2;
50module_param(rc_key_repeat_count, int, 0644);
51MODULE_PARM_DESC(rc_key_repeat_count, "how many key repeats will be dropped before passing the key event again (default: 2)");
52
53/* Vendor IDs */
54#define USB_VID_ADSTECH 0x06e1
55#define USB_VID_ANCHOR 0x0547
56#define USB_VID_AVERMEDIA 0x14aa
57#define USB_VID_COMPRO 0x185b
58#define USB_VID_COMPRO_UNK 0x145f
59#define USB_VID_CYPRESS 0x04b4
60#define USB_VID_DIBCOM 0x10b8
61#define USB_VID_EMPIA 0xeb1a
62#define USB_VID_GRANDTEC 0x5032
63#define USB_VID_HANFTEK 0x15f4
64#define USB_VID_HAUPPAUGE 0x2040
65#define USB_VID_HYPER_PALTEK 0x1025
66#define USB_VID_IMC_NETWORKS 0x13d3
67#define USB_VID_TWINHAN 0x1822
68#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
69
70/* Product IDs */
71#define USB_PID_ADSTECH_USB2_COLD 0xa333
72#define USB_PID_ADSTECH_USB2_WARM 0xa334
73#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001
74#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002
75#define USB_PID_COMPRO_DVBU2000_COLD 0xd000
76#define USB_PID_COMPRO_DVBU2000_WARM 0xd001
77#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c
78#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d
79#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
80#define USB_PID_DIBCOM_MOD3000_WARM 0x0bb9
81#define USB_PID_DIBCOM_MOD3001_COLD 0x0bc6
82#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7
83#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
84#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
85#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
86#define USB_PID_KWORLD_VSTREAM_COLD 0x17de
87#define USB_PID_KWORLD_VSTREAM_WARM 0x17df
88#define USB_PID_TWINHAN_VP7041_COLD 0x3201
89#define USB_PID_TWINHAN_VP7041_WARM 0x3202
90#define USB_PID_ULTIMA_TVBOX_COLD 0x8105
91#define USB_PID_ULTIMA_TVBOX_WARM 0x8106
92#define USB_PID_ULTIMA_TVBOX_AN2235_COLD 0x8107
93#define USB_PID_ULTIMA_TVBOX_AN2235_WARM 0x8108
94#define USB_PID_ULTIMA_TVBOX_ANCHOR_COLD 0x2235
95#define USB_PID_ULTIMA_TVBOX_USB2_COLD 0x8109
96#define USB_PID_ULTIMA_TVBOX_USB2_FX_COLD 0x8613
97#define USB_PID_ULTIMA_TVBOX_USB2_FX_WARM 0x1002
98#define USB_PID_UNK_HYPER_PALTEK_COLD 0x005e
99#define USB_PID_UNK_HYPER_PALTEK_WARM 0x005f
100#define USB_PID_HANFTEK_UMT_010_COLD 0x0001
101#define USB_PID_HANFTEK_UMT_010_WARM 0x0015
102#define USB_PID_YAKUMO_DTT200U_COLD 0x0201
103#define USB_PID_YAKUMO_DTT200U_WARM 0x0301
104#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300
105#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301
106
107/* USB Driver stuff
108 * table of devices that this driver is working with
109 *
110 * ATTENTION: Never ever change the order of this table, the particular
111 * devices depend on this order
112 *
113 * Each entry is used as a reference in the device_struct. Currently this is
114 * the only non-redundant way of assigning USB ids to actual devices I'm aware
115 * of, because there is only one place in the code where the assignment of
116 * vendor and product id is done, here.
117 */
118static struct usb_device_id dib_table [] = {
119/* 00 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_DVBT_USB_COLD)},
120/* 01 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_DVBT_USB_WARM)},
121/* 02 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_YAKUMO_DTT200U_COLD) },
122/* 03 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_YAKUMO_DTT200U_WARM) },
123
124/* 04 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_COLD) },
125/* 05 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_WARM) },
126/* 06 */ { USB_DEVICE(USB_VID_COMPRO_UNK, USB_PID_COMPRO_DVBU2000_UNK_COLD) },
127/* 07 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3000_COLD) },
128/* 08 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3000_WARM) },
129/* 09 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_COLD) },
130/* 10 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_WARM) },
131/* 11 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_KWORLD_VSTREAM_COLD) },
132/* 12 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_KWORLD_VSTREAM_WARM) },
133/* 13 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_GRANDTEC_DVBT_USB_COLD) },
134/* 14 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_GRANDTEC_DVBT_USB_WARM) },
135/* 15 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_DIBCOM_MOD3000_COLD) },
136/* 16 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_DIBCOM_MOD3000_WARM) },
137/* 17 */ { USB_DEVICE(USB_VID_HYPER_PALTEK, USB_PID_UNK_HYPER_PALTEK_COLD) },
138/* 18 */ { USB_DEVICE(USB_VID_HYPER_PALTEK, USB_PID_UNK_HYPER_PALTEK_WARM) },
139/* 19 */ { USB_DEVICE(USB_VID_IMC_NETWORKS, USB_PID_TWINHAN_VP7041_COLD) },
140/* 20 */ { USB_DEVICE(USB_VID_IMC_NETWORKS, USB_PID_TWINHAN_VP7041_WARM) },
141/* 21 */ { USB_DEVICE(USB_VID_TWINHAN, USB_PID_TWINHAN_VP7041_COLD) },
142/* 22 */ { USB_DEVICE(USB_VID_TWINHAN, USB_PID_TWINHAN_VP7041_WARM) },
143/* 23 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_COLD) },
144/* 24 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_WARM) },
145/* 25 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_COLD) },
146/* 26 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_WARM) },
147/* 27 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_USB2_COLD) },
148
149/* 28 */ { USB_DEVICE(USB_VID_HANFTEK, USB_PID_HANFTEK_UMT_010_COLD) },
150/* 29 */ { USB_DEVICE(USB_VID_HANFTEK, USB_PID_HANFTEK_UMT_010_WARM) },
151
152/* 30 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_COLD) },
153/* 31 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_WARM) },
154/* 32 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_COLD) },
155/* 33 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_WARM) },
156/*
157 * activate the following define when you have one of the devices and want to
158 * build it from build-2.6 in dvb-kernel
159 */
160// #define CONFIG_DVB_DIBUSB_MISDESIGNED_DEVICES
161#ifdef CONFIG_DVB_DIBUSB_MISDESIGNED_DEVICES
162/* 34 */ { USB_DEVICE(USB_VID_ANCHOR, USB_PID_ULTIMA_TVBOX_ANCHOR_COLD) },
163/* 35 */ { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ULTIMA_TVBOX_USB2_FX_COLD) },
164/* 36 */ { USB_DEVICE(USB_VID_ANCHOR, USB_PID_ULTIMA_TVBOX_USB2_FX_WARM) },
165/* 37 */ { USB_DEVICE(USB_VID_ANCHOR, USB_PID_DIBCOM_ANCHOR_2135_COLD) },
166#endif
167 { } /* Terminating entry */
168};
169
170MODULE_DEVICE_TABLE (usb, dib_table);
171
172static struct dibusb_usb_controller dibusb_usb_ctrl[] = {
173 { .name = "Cypress AN2135", .cpu_cs_register = 0x7f92 },
174 { .name = "Cypress AN2235", .cpu_cs_register = 0x7f92 },
175 { .name = "Cypress FX2", .cpu_cs_register = 0xe600 },
176};
177
178struct dibusb_tuner dibusb_tuner[] = {
179 { DIBUSB_TUNER_CABLE_THOMSON,
180 0x61
181 },
182 { DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5,
183 0x60
184 },
185 { DIBUSB_TUNER_CABLE_LG_TDTP_E102P,
186 0x61
187 },
188 { DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5,
189 0x60
190 },
191};
192
193static struct dibusb_demod dibusb_demod[] = {
194 { DIBUSB_DIB3000MB,
195 16,
196 { 0x8, 0 },
197 },
198 { DIBUSB_DIB3000MC,
199 32,
200 { 0x9, 0xa, 0xb, 0xc },
201 },
202 { DIBUSB_MT352,
203 254,
204 { 0xf, 0 },
205 },
206 { DTT200U_FE,
207 8,
208 { 0xff,0 }, /* there is no i2c bus in this device */
209 }
210};
211
212static struct dibusb_device_class dibusb_device_classes[] = {
213 { .id = DIBUSB1_1, .usb_ctrl = &dibusb_usb_ctrl[0],
214 .firmware = "dvb-dibusb-5.0.0.11.fw",
215 .pipe_cmd = 0x01, .pipe_data = 0x02,
216 .urb_count = 7, .urb_buffer_size = 4096,
217 DIBUSB_RC_NEC_PROTOCOL,
218 &dibusb_demod[DIBUSB_DIB3000MB],
219 &dibusb_tuner[DIBUSB_TUNER_CABLE_THOMSON],
220 },
221 { DIBUSB1_1_AN2235, &dibusb_usb_ctrl[1],
222 "dvb-dibusb-an2235-1.fw",
223 0x01, 0x02,
224 7, 4096,
225 DIBUSB_RC_NEC_PROTOCOL,
226 &dibusb_demod[DIBUSB_DIB3000MB],
227 &dibusb_tuner[DIBUSB_TUNER_CABLE_THOMSON],
228 },
229 { DIBUSB2_0,&dibusb_usb_ctrl[2],
230 "dvb-dibusb-6.0.0.5.fw",
231 0x01, 0x06,
232 7, 4096,
233 DIBUSB_RC_NEC_PROTOCOL,
234 &dibusb_demod[DIBUSB_DIB3000MC],
235 &dibusb_tuner[DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5],
236 },
237 { UMT2_0, &dibusb_usb_ctrl[2],
238 "dvb-dibusb-umt-2.fw",
239 0x01, 0x06,
240 20, 512,
241 DIBUSB_RC_NO,
242 &dibusb_demod[DIBUSB_MT352],
243 &dibusb_tuner[DIBUSB_TUNER_CABLE_LG_TDTP_E102P],
244 },
245 { DIBUSB2_0B,&dibusb_usb_ctrl[2],
246 "dvb-dibusb-adstech-usb2-1.fw",
247 0x01, 0x06,
248 7, 4096,
249 DIBUSB_RC_NEC_PROTOCOL,
250 &dibusb_demod[DIBUSB_DIB3000MB],
251 &dibusb_tuner[DIBUSB_TUNER_CABLE_THOMSON],
252 },
253 { NOVAT_USB2,&dibusb_usb_ctrl[2],
254 "dvb-dibusb-nova-t-1.fw",
255 0x01, 0x06,
256 7, 4096,
257 DIBUSB_RC_HAUPPAUGE_PROTO,
258 &dibusb_demod[DIBUSB_DIB3000MC],
259 &dibusb_tuner[DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5],
260 },
261 { DTT200U,&dibusb_usb_ctrl[2],
262 "dvb-dtt200u-1.fw",
263 0x01, 0x02,
264 7, 4096,
265 DIBUSB_RC_NO,
266 &dibusb_demod[DTT200U_FE],
267 NULL, /* no explicit tuner/pll-programming necessary (it has the ENV57H1XD5) */
268 },
269};
270
271static struct dibusb_usb_device dibusb_devices[] = {
272 { "TwinhanDTV USB1.1 / Magic Box / HAMA USB1.1 DVB-T device",
273 &dibusb_device_classes[DIBUSB1_1],
274 { &dib_table[19], &dib_table[21], NULL},
275 { &dib_table[20], &dib_table[22], NULL},
276 },
277 { "KWorld V-Stream XPERT DTV - DVB-T USB1.1",
278 &dibusb_device_classes[DIBUSB1_1],
279 { &dib_table[11], NULL },
280 { &dib_table[12], NULL },
281 },
282 { "Grandtec USB1.1 DVB-T",
283 &dibusb_device_classes[DIBUSB1_1],
284 { &dib_table[13], &dib_table[15], NULL },
285 { &dib_table[14], &dib_table[16], NULL },
286 },
287 { "DiBcom USB1.1 DVB-T reference design (MOD3000)",
288 &dibusb_device_classes[DIBUSB1_1],
289 { &dib_table[7], NULL },
290 { &dib_table[8], NULL },
291 },
292 { "Artec T1 USB1.1 TVBOX with AN2135",
293 &dibusb_device_classes[DIBUSB1_1],
294 { &dib_table[23], NULL },
295 { &dib_table[24], NULL },
296 },
297 { "Artec T1 USB1.1 TVBOX with AN2235",
298 &dibusb_device_classes[DIBUSB1_1_AN2235],
299 { &dib_table[25], NULL },
300 { &dib_table[26], NULL },
301 },
302 { "Avermedia AverTV DVBT USB1.1",
303 &dibusb_device_classes[DIBUSB1_1],
304 { &dib_table[0], NULL },
305 { &dib_table[1], NULL },
306 },
307 { "Compro Videomate DVB-U2000 - DVB-T USB1.1 (please confirm to linux-dvb)",
308 &dibusb_device_classes[DIBUSB1_1],
309 { &dib_table[4], &dib_table[6], NULL},
310 { &dib_table[5], NULL },
311 },
312 { "Unkown USB1.1 DVB-T device ???? please report the name to the author",
313 &dibusb_device_classes[DIBUSB1_1],
314 { &dib_table[17], NULL },
315 { &dib_table[18], NULL },
316 },
317 { "DiBcom USB2.0 DVB-T reference design (MOD3000P)",
318 &dibusb_device_classes[DIBUSB2_0],
319 { &dib_table[9], NULL },
320 { &dib_table[10], NULL },
321 },
322 { "Artec T1 USB2.0 TVBOX (please report the warm ID)",
323 &dibusb_device_classes[DIBUSB2_0],
324 { &dib_table[27], NULL },
325 { NULL },
326 },
327 { "Hauppauge WinTV NOVA-T USB2",
328 &dibusb_device_classes[NOVAT_USB2],
329 { &dib_table[30], NULL },
330 { &dib_table[31], NULL },
331 },
332 { "DTT200U (Yakumo/Hama/Typhoon) DVB-T USB2.0",
333 &dibusb_device_classes[DTT200U],
334 { &dib_table[2], NULL },
335 { &dib_table[3], NULL },
336 },
337 { "Hanftek UMT-010 DVB-T USB2.0",
338 &dibusb_device_classes[UMT2_0],
339 { &dib_table[28], NULL },
340 { &dib_table[29], NULL },
341 },
342 { "KWorld/ADSTech Instant DVB-T USB 2.0",
343 &dibusb_device_classes[DIBUSB2_0B],
344 { &dib_table[32], NULL },
345 { &dib_table[33], NULL }, /* device ID with default DIBUSB2_0-firmware */
346 },
347#ifdef CONFIG_DVB_DIBUSB_MISDESIGNED_DEVICES
348 { "Artec T1 USB1.1 TVBOX with AN2235 (misdesigned)",
349 &dibusb_device_classes[DIBUSB1_1_AN2235],
350 { &dib_table[34], NULL },
351 { NULL },
352 },
353 { "Artec T1 USB2.0 TVBOX with FX2 IDs (misdesigned, please report the warm ID)",
354 &dibusb_device_classes[DTT200U],
355 { &dib_table[35], NULL },
356 { &dib_table[36], NULL }, /* undefined, it could be that the device will get another USB ID in warm state */
357 },
358 { "DiBcom USB1.1 DVB-T reference design (MOD3000) with AN2135 default IDs",
359 &dibusb_device_classes[DIBUSB1_1],
360 { &dib_table[37], NULL },
361 { NULL },
362 },
363#endif
364};
365
366static int dibusb_exit(struct usb_dibusb *dib)
367{
368 deb_info("init_state before exiting everything: %x\n",dib->init_state);
369 dibusb_remote_exit(dib);
370 dibusb_fe_exit(dib);
371 dibusb_i2c_exit(dib);
372 dibusb_dvb_exit(dib);
373 dibusb_urb_exit(dib);
374 deb_info("init_state should be zero now: %x\n",dib->init_state);
375 dib->init_state = DIBUSB_STATE_INIT;
376 kfree(dib);
377 return 0;
378}
379
380static int dibusb_init(struct usb_dibusb *dib)
381{
382 int ret = 0;
383 sema_init(&dib->usb_sem, 1);
384 sema_init(&dib->i2c_sem, 1);
385
386 dib->init_state = DIBUSB_STATE_INIT;
387
388 if ((ret = dibusb_urb_init(dib)) ||
389 (ret = dibusb_dvb_init(dib)) ||
390 (ret = dibusb_i2c_init(dib))) {
391 dibusb_exit(dib);
392 return ret;
393 }
394
395 if ((ret = dibusb_fe_init(dib)))
396 err("could not initialize a frontend.");
397
398 if ((ret = dibusb_remote_init(dib)))
399 err("could not initialize remote control.");
400
401 return 0;
402}
403
404static struct dibusb_usb_device * dibusb_device_class_quirk(struct usb_device *udev, struct dibusb_usb_device *dev)
405{
406 int i;
407
408 /* Quirk for the Kworld/ADSTech Instant USB2.0 device. It has the same USB
409 * IDs like the USB1.1 KWorld after loading the firmware. Which is a bad
410 * idea and make this quirk necessary.
411 */
412 if (dev->dev_cl->id == DIBUSB1_1 && udev->speed == USB_SPEED_HIGH) {
413 info("this seems to be the Kworld/ADSTech Instant USB2.0 device or equal.");
414 for (i = 0; i < sizeof(dibusb_devices)/sizeof(struct dibusb_usb_device); i++) {
415 if (dibusb_devices[i].dev_cl->id == DIBUSB2_0B) {
416 dev = &dibusb_devices[i];
417 break;
418 }
419 }
420 }
421
422 return dev;
423}
424
425static struct dibusb_usb_device * dibusb_find_device (struct usb_device *udev,int *cold)
426{
427 int i,j;
428 struct dibusb_usb_device *dev = NULL;
429 *cold = -1;
430
431 for (i = 0; i < sizeof(dibusb_devices)/sizeof(struct dibusb_usb_device); i++) {
432 for (j = 0; j < DIBUSB_ID_MAX_NUM && dibusb_devices[i].cold_ids[j] != NULL; j++) {
433 deb_info("check for cold %x %x\n",dibusb_devices[i].cold_ids[j]->idVendor, dibusb_devices[i].cold_ids[j]->idProduct);
434 if (dibusb_devices[i].cold_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
435 dibusb_devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
436 *cold = 1;
437 dev = &dibusb_devices[i];
438 break;
439 }
440 }
441
442 if (dev != NULL)
443 break;
444
445 for (j = 0; j < DIBUSB_ID_MAX_NUM && dibusb_devices[i].warm_ids[j] != NULL; j++) {
446 deb_info("check for warm %x %x\n",dibusb_devices[i].warm_ids[j]->idVendor, dibusb_devices[i].warm_ids[j]->idProduct);
447 if (dibusb_devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
448 dibusb_devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
449 *cold = 0;
450 dev = &dibusb_devices[i];
451 break;
452 }
453 }
454 }
455
456 if (dev != NULL)
457 dev = dibusb_device_class_quirk(udev,dev);
458
459 return dev;
460}
461
462/*
463 * USB
464 */
465static int dibusb_probe(struct usb_interface *intf,
466 const struct usb_device_id *id)
467{
468 struct usb_device *udev = interface_to_usbdev(intf);
469 struct usb_dibusb *dib = NULL;
470 struct dibusb_usb_device *dibdev = NULL;
471
472 int ret = -ENOMEM,cold=0;
473
474 if ((dibdev = dibusb_find_device(udev,&cold)) == NULL) {
475 err("something went very wrong, "
476 "unknown product ID: %.4x",le16_to_cpu(udev->descriptor.idProduct));
477 return -ENODEV;
478 }
479
480 if (cold == 1) {
481 info("found a '%s' in cold state, will try to load a firmware",dibdev->name);
482 ret = dibusb_loadfirmware(udev,dibdev);
483 } else {
484 info("found a '%s' in warm state.",dibdev->name);
485 dib = kmalloc(sizeof(struct usb_dibusb),GFP_KERNEL);
486 if (dib == NULL) {
487 err("no memory");
488 return ret;
489 }
490 memset(dib,0,sizeof(struct usb_dibusb));
491
492 dib->udev = udev;
493 dib->dibdev = dibdev;
494
495 /* store parameters to structures */
496 dib->rc_query_interval = rc_query_interval;
497 dib->pid_parse = pid_parse;
498 dib->rc_key_repeat_count = rc_key_repeat_count;
499
500 usb_set_intfdata(intf, dib);
501
502 ret = dibusb_init(dib);
503 }
504
505 if (ret == 0)
506 info("%s successfully initialized and connected.",dibdev->name);
507 else
508 info("%s error while loading driver (%d)",dibdev->name,ret);
509 return ret;
510}
511
512static void dibusb_disconnect(struct usb_interface *intf)
513{
514 struct usb_dibusb *dib = usb_get_intfdata(intf);
515 const char *name = DRIVER_DESC;
516
517 usb_set_intfdata(intf,NULL);
518 if (dib != NULL && dib->dibdev != NULL) {
519 name = dib->dibdev->name;
520 dibusb_exit(dib);
521 }
522 info("%s successfully deinitialized and disconnected.",name);
523
524}
525
526/* usb specific object needed to register this driver with the usb subsystem */
527static struct usb_driver dibusb_driver = {
528 .owner = THIS_MODULE,
529 .name = DRIVER_DESC,
530 .probe = dibusb_probe,
531 .disconnect = dibusb_disconnect,
532 .id_table = dib_table,
533};
534
535/* module stuff */
536static int __init usb_dibusb_init(void)
537{
538 int result;
539 if ((result = usb_register(&dibusb_driver))) {
540 err("usb_register failed. Error number %d",result);
541 return result;
542 }
543
544 return 0;
545}
546
547static void __exit usb_dibusb_exit(void)
548{
549 /* deregister this driver from the USB subsystem */
550 usb_deregister(&dibusb_driver);
551}
552
553module_init (usb_dibusb_init);
554module_exit (usb_dibusb_exit);
555
556MODULE_AUTHOR(DRIVER_AUTHOR);
557MODULE_DESCRIPTION(DRIVER_DESC);
558MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dibusb/dvb-dibusb-dvb.c b/drivers/media/dvb/dibusb/dvb-dibusb-dvb.c
deleted file mode 100644
index 04e54ec093f0..000000000000
--- a/drivers/media/dvb/dibusb/dvb-dibusb-dvb.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 * dvb-dibusb-dvb.c is part of the driver for mobile USB Budget DVB-T devices
3 * based on reference design made by DiBcom (http://www.dibcom.fr/)
4 *
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 *
7 * see dvb-dibusb-core.c for more copyright details.
8 *
9 * This file contains functions for initializing and handling the
10 * linux-dvb API.
11 */
12#include "dvb-dibusb.h"
13
14#include <linux/usb.h>
15#include <linux/version.h>
16
17static u32 urb_compl_count;
18
19/*
20 * MPEG2 TS DVB stuff
21 */
22void dibusb_urb_complete(struct urb *urb, struct pt_regs *ptregs)
23{
24 struct usb_dibusb *dib = urb->context;
25
26 deb_ts("urb complete feedcount: %d, status: %d, length: %d\n",dib->feedcount,urb->status,
27 urb->actual_length);
28
29 urb_compl_count++;
30 if (urb_compl_count % 1000 == 0)
31 deb_info("%d urbs completed so far.\n",urb_compl_count);
32
33 switch (urb->status) {
34 case 0: /* success */
35 case -ETIMEDOUT: /* NAK */
36 break;
37 case -ECONNRESET: /* kill */
38 case -ENOENT:
39 case -ESHUTDOWN:
40 return;
41 default: /* error */
42 deb_ts("urb completition error %d.", urb->status);
43 break;
44 }
45
46 if (dib->feedcount > 0 && urb->actual_length > 0) {
47 if (dib->init_state & DIBUSB_STATE_DVB)
48 dvb_dmx_swfilter(&dib->demux, (u8*) urb->transfer_buffer,urb->actual_length);
49 } else
50 deb_ts("URB dropped because of feedcount.\n");
51
52 usb_submit_urb(urb,GFP_ATOMIC);
53}
54
55static int dibusb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
56{
57 struct usb_dibusb *dib = dvbdmxfeed->demux->priv;
58 int newfeedcount;
59
60 if (dib == NULL)
61 return -ENODEV;
62
63 newfeedcount = dib->feedcount + (onoff ? 1 : -1);
64
65 /*
66 * stop feed before setting a new pid if there will be no pid anymore
67 */
68 if (newfeedcount == 0) {
69 deb_ts("stop feeding\n");
70 if (dib->xfer_ops.fifo_ctrl != NULL) {
71 if (dib->xfer_ops.fifo_ctrl(dib->fe,0)) {
72 err("error while inhibiting fifo.");
73 return -ENODEV;
74 }
75 }
76 dibusb_streaming(dib,0);
77 }
78
79 dib->feedcount = newfeedcount;
80
81 /* activate the pid on the device specific pid_filter */
82 deb_ts("setting pid: %5d %04x at index %d '%s'\n",dvbdmxfeed->pid,dvbdmxfeed->pid,dvbdmxfeed->index,onoff ? "on" : "off");
83 if (dib->pid_parse && dib->xfer_ops.pid_ctrl != NULL)
84 dib->xfer_ops.pid_ctrl(dib->fe,dvbdmxfeed->index,dvbdmxfeed->pid,onoff);
85
86 /*
87 * start the feed if this was the first pid to set and there is still a pid
88 * for reception.
89 */
90 if (dib->feedcount == onoff && dib->feedcount > 0) {
91
92 deb_ts("controlling pid parser\n");
93 if (dib->xfer_ops.pid_parse != NULL) {
94 if (dib->xfer_ops.pid_parse(dib->fe,dib->pid_parse) < 0) {
95 err("could not handle pid_parser");
96 }
97 }
98
99 deb_ts("start feeding\n");
100 if (dib->xfer_ops.fifo_ctrl != NULL) {
101 if (dib->xfer_ops.fifo_ctrl(dib->fe,1)) {
102 err("error while enabling fifo.");
103 return -ENODEV;
104 }
105 }
106 dibusb_streaming(dib,1);
107 }
108 return 0;
109}
110
111static int dibusb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
112{
113 deb_ts("start pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid,dvbdmxfeed->type);
114 return dibusb_ctrl_feed(dvbdmxfeed,1);
115}
116
117static int dibusb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
118{
119 deb_ts("stop pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid, dvbdmxfeed->type);
120 return dibusb_ctrl_feed(dvbdmxfeed,0);
121}
122
123int dibusb_dvb_init(struct usb_dibusb *dib)
124{
125 int ret;
126
127 urb_compl_count = 0;
128
129 if ((ret = dvb_register_adapter(&dib->adapter, DRIVER_DESC,
130 THIS_MODULE)) < 0) {
131 deb_info("dvb_register_adapter failed: error %d", ret);
132 goto err;
133 }
134 dib->adapter->priv = dib;
135
136/* i2c is done in dibusb_i2c_init */
137
138 dib->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
139
140 dib->demux.priv = (void *)dib;
141 /* get pidcount from demod */
142 dib->demux.feednum = dib->demux.filternum = 255;
143 dib->demux.start_feed = dibusb_start_feed;
144 dib->demux.stop_feed = dibusb_stop_feed;
145 dib->demux.write_to_decoder = NULL;
146 if ((ret = dvb_dmx_init(&dib->demux)) < 0) {
147 err("dvb_dmx_init failed: error %d",ret);
148 goto err_dmx;
149 }
150
151 dib->dmxdev.filternum = dib->demux.filternum;
152 dib->dmxdev.demux = &dib->demux.dmx;
153 dib->dmxdev.capabilities = 0;
154 if ((ret = dvb_dmxdev_init(&dib->dmxdev, dib->adapter)) < 0) {
155 err("dvb_dmxdev_init failed: error %d",ret);
156 goto err_dmx_dev;
157 }
158
159 dvb_net_init(dib->adapter, &dib->dvb_net, &dib->demux.dmx);
160
161 goto success;
162err_dmx_dev:
163 dvb_dmx_release(&dib->demux);
164err_dmx:
165 dvb_unregister_adapter(dib->adapter);
166err:
167 return ret;
168success:
169 dib->init_state |= DIBUSB_STATE_DVB;
170 return 0;
171}
172
173int dibusb_dvb_exit(struct usb_dibusb *dib)
174{
175 if (dib->init_state & DIBUSB_STATE_DVB) {
176 dib->init_state &= ~DIBUSB_STATE_DVB;
177 deb_info("unregistering DVB part\n");
178 dvb_net_release(&dib->dvb_net);
179 dib->demux.dmx.close(&dib->demux.dmx);
180 dvb_dmxdev_release(&dib->dmxdev);
181 dvb_dmx_release(&dib->demux);
182 dvb_unregister_adapter(dib->adapter);
183 }
184 return 0;
185}
diff --git a/drivers/media/dvb/dibusb/dvb-dibusb-fe-i2c.c b/drivers/media/dvb/dibusb/dvb-dibusb-fe-i2c.c
deleted file mode 100644
index 2ed89488c7c4..000000000000
--- a/drivers/media/dvb/dibusb/dvb-dibusb-fe-i2c.c
+++ /dev/null
@@ -1,582 +0,0 @@
1/*
2 * dvb-dibusb-fe-i2c.c is part of the driver for mobile USB Budget DVB-T devices
3 * based on reference design made by DiBcom (http://www.dibcom.fr/)
4 *
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 *
7 * see dvb-dibusb-core.c for more copyright details.
8 *
9 * This file contains functions for attaching, initializing of an appropriate
10 * demodulator/frontend. I2C-stuff is also located here.
11 *
12 */
13#include "dvb-dibusb.h"
14
15#include <linux/usb.h>
16
17static int dibusb_i2c_msg(struct usb_dibusb *dib, u8 addr,
18 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
19{
20 u8 sndbuf[wlen+4]; /* lead(1) devaddr,direction(1) addr(2) data(wlen) (len(2) (when reading)) */
21 /* write only ? */
22 int wo = (rbuf == NULL || rlen == 0),
23 len = 2 + wlen + (wo ? 0 : 2);
24
25 sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
26 sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
27
28 memcpy(&sndbuf[2],wbuf,wlen);
29
30 if (!wo) {
31 sndbuf[wlen+2] = (rlen >> 8) & 0xff;
32 sndbuf[wlen+3] = rlen & 0xff;
33 }
34
35 return dibusb_readwrite_usb(dib,sndbuf,len,rbuf,rlen);
36}
37
38/*
39 * I2C master xfer function
40 */
41static int dibusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg *msg,int num)
42{
43 struct usb_dibusb *dib = i2c_get_adapdata(adap);
44 int i;
45
46 if (down_interruptible(&dib->i2c_sem) < 0)
47 return -EAGAIN;
48
49 if (num > 2)
50 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
51
52 for (i = 0; i < num; i++) {
53 /* write/read request */
54 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
55 if (dibusb_i2c_msg(dib, msg[i].addr, msg[i].buf,msg[i].len,
56 msg[i+1].buf,msg[i+1].len) < 0)
57 break;
58 i++;
59 } else
60 if (dibusb_i2c_msg(dib, msg[i].addr, msg[i].buf,msg[i].len,NULL,0) < 0)
61 break;
62 }
63
64 up(&dib->i2c_sem);
65 return i;
66}
67
68static u32 dibusb_i2c_func(struct i2c_adapter *adapter)
69{
70 return I2C_FUNC_I2C;
71}
72
73static struct i2c_algorithm dibusb_algo = {
74 .name = "DiBcom USB i2c algorithm",
75 .id = I2C_ALGO_BIT,
76 .master_xfer = dibusb_i2c_xfer,
77 .functionality = dibusb_i2c_func,
78};
79
80static int dibusb_general_demod_init(struct dvb_frontend *fe);
81static u8 dibusb_general_pll_addr(struct dvb_frontend *fe);
82static int dibusb_general_pll_init(struct dvb_frontend *fe, u8 pll_buf[5]);
83static int dibusb_general_pll_set(struct dvb_frontend *fe,
84 struct dvb_frontend_parameters* params, u8 pll_buf[5]);
85
86static struct mt352_config mt352_hanftek_umt_010_config = {
87 .demod_address = 0x1e,
88 .demod_init = dibusb_general_demod_init,
89 .pll_set = dibusb_general_pll_set,
90};
91
92static int dibusb_tuner_quirk(struct usb_dibusb *dib)
93{
94 switch (dib->dibdev->dev_cl->id) {
95 case DIBUSB1_1: /* some these device have the ENV77H11D5 and some the THOMSON CABLE */
96 case DIBUSB1_1_AN2235: { /* actually its this device, but in warm state they are indistinguishable */
97 struct dibusb_tuner *t;
98 u8 b[2] = { 0,0 } ,b2[1];
99 struct i2c_msg msg[2] = {
100 { .flags = 0, .buf = b, .len = 2 },
101 { .flags = I2C_M_RD, .buf = b2, .len = 1},
102 };
103
104 t = &dibusb_tuner[DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5];
105
106 msg[0].addr = msg[1].addr = t->pll_addr;
107
108 if (dib->xfer_ops.tuner_pass_ctrl != NULL)
109 dib->xfer_ops.tuner_pass_ctrl(dib->fe,1,t->pll_addr);
110 dibusb_i2c_xfer(&dib->i2c_adap,msg,2);
111 if (dib->xfer_ops.tuner_pass_ctrl != NULL)
112 dib->xfer_ops.tuner_pass_ctrl(dib->fe,0,t->pll_addr);
113
114 if (b2[0] == 0xfe)
115 info("this device has the Thomson Cable onboard. Which is default.");
116 else {
117 dib->tuner = t;
118 info("this device has the Panasonic ENV77H11D5 onboard.");
119 }
120 break;
121 }
122 default:
123 break;
124 }
125 return 0;
126}
127
128int dibusb_fe_init(struct usb_dibusb* dib)
129{
130 struct dib3000_config demod_cfg;
131 int i;
132
133 if (dib->init_state & DIBUSB_STATE_I2C) {
134 for (i = 0; i < sizeof(dib->dibdev->dev_cl->demod->i2c_addrs) / sizeof(unsigned char) &&
135 dib->dibdev->dev_cl->demod->i2c_addrs[i] != 0; i++) {
136
137 demod_cfg.demod_address = dib->dibdev->dev_cl->demod->i2c_addrs[i];
138 demod_cfg.pll_addr = dibusb_general_pll_addr;
139 demod_cfg.pll_set = dibusb_general_pll_set;
140 demod_cfg.pll_init = dibusb_general_pll_init;
141
142 deb_info("demod id: %d %d\n",dib->dibdev->dev_cl->demod->id,DTT200U_FE);
143
144 switch (dib->dibdev->dev_cl->demod->id) {
145 case DIBUSB_DIB3000MB:
146 dib->fe = dib3000mb_attach(&demod_cfg,&dib->i2c_adap,&dib->xfer_ops);
147 break;
148 case DIBUSB_DIB3000MC:
149 dib->fe = dib3000mc_attach(&demod_cfg,&dib->i2c_adap,&dib->xfer_ops);
150 break;
151 case DIBUSB_MT352:
152 mt352_hanftek_umt_010_config.demod_address = dib->dibdev->dev_cl->demod->i2c_addrs[i];
153 dib->fe = mt352_attach(&mt352_hanftek_umt_010_config, &dib->i2c_adap);
154 break;
155 case DTT200U_FE:
156 dib->fe = dtt200u_fe_attach(dib,&dib->xfer_ops);
157 break;
158 }
159 if (dib->fe != NULL) {
160 info("found demodulator at i2c address 0x%x",dib->dibdev->dev_cl->demod->i2c_addrs[i]);
161 break;
162 }
163 }
164 /* if a frontend was found */
165 if (dib->fe != NULL) {
166 if (dib->fe->ops->sleep != NULL)
167 dib->fe_sleep = dib->fe->ops->sleep;
168 dib->fe->ops->sleep = dibusb_hw_sleep;
169
170 if (dib->fe->ops->init != NULL )
171 dib->fe_init = dib->fe->ops->init;
172 dib->fe->ops->init = dibusb_hw_wakeup;
173
174 /* setting the default tuner */
175 dib->tuner = dib->dibdev->dev_cl->tuner;
176
177 /* check which tuner is mounted on this device, in case this is unsure */
178 dibusb_tuner_quirk(dib);
179 }
180 }
181 if (dib->fe == NULL) {
182 err("A frontend driver was not found for device '%s'.",
183 dib->dibdev->name);
184 return -ENODEV;
185 } else {
186 if (dvb_register_frontend(dib->adapter, dib->fe)) {
187 err("Frontend registration failed.");
188 if (dib->fe->ops->release)
189 dib->fe->ops->release(dib->fe);
190 dib->fe = NULL;
191 return -ENODEV;
192 }
193 }
194
195 return 0;
196}
197
198int dibusb_fe_exit(struct usb_dibusb *dib)
199{
200 if (dib->fe != NULL)
201 dvb_unregister_frontend(dib->fe);
202 return 0;
203}
204
205int dibusb_i2c_init(struct usb_dibusb *dib)
206{
207 int ret = 0;
208
209 dib->adapter->priv = dib;
210
211 strncpy(dib->i2c_adap.name,dib->dibdev->name,I2C_NAME_SIZE);
212#ifdef I2C_ADAP_CLASS_TV_DIGITAL
213 dib->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
214#else
215 dib->i2c_adap.class = I2C_CLASS_TV_DIGITAL,
216#endif
217 dib->i2c_adap.algo = &dibusb_algo;
218 dib->i2c_adap.algo_data = NULL;
219 dib->i2c_adap.id = I2C_ALGO_BIT;
220
221 i2c_set_adapdata(&dib->i2c_adap, dib);
222
223 if ((ret = i2c_add_adapter(&dib->i2c_adap)) < 0)
224 err("could not add i2c adapter");
225
226 dib->init_state |= DIBUSB_STATE_I2C;
227
228 return ret;
229}
230
231int dibusb_i2c_exit(struct usb_dibusb *dib)
232{
233 if (dib->init_state & DIBUSB_STATE_I2C)
234 i2c_del_adapter(&dib->i2c_adap);
235 dib->init_state &= ~DIBUSB_STATE_I2C;
236 return 0;
237}
238
239
240/* pll stuff, maybe removed soon (thx to Gerd/Andrew in advance) */
241static int thomson_cable_eu_pll_set(struct dvb_frontend_parameters *fep, u8 pllbuf[4])
242{
243 u32 tfreq = (fep->frequency + 36125000) / 62500;
244 int vu,p0,p1,p2;
245
246 if (fep->frequency > 403250000)
247 vu = 1, p2 = 1, p1 = 0, p0 = 1;
248 else if (fep->frequency > 115750000)
249 vu = 0, p2 = 1, p1 = 1, p0 = 0;
250 else if (fep->frequency > 44250000)
251 vu = 0, p2 = 0, p1 = 1, p0 = 1;
252 else
253 return -EINVAL;
254
255 pllbuf[0] = (tfreq >> 8) & 0x7f;
256 pllbuf[1] = tfreq & 0xff;
257 pllbuf[2] = 0x8e;
258 pllbuf[3] = (vu << 7) | (p2 << 2) | (p1 << 1) | p0;
259 return 0;
260}
261
262static int panasonic_cofdm_env57h1xd5_pll_set(struct dvb_frontend_parameters *fep, u8 pllbuf[4])
263{
264 u32 freq_khz = fep->frequency / 1000;
265 u32 tfreq = ((freq_khz + 36125)*6 + 500) / 1000;
266 u8 TA, T210, R210, ctrl1, cp210, p4321;
267 if (freq_khz > 858000) {
268 err("frequency cannot be larger than 858 MHz.");
269 return -EINVAL;
270 }
271
272 // contol data 1 : 1 | T/A=1 | T2,T1,T0 = 0,0,0 | R2,R1,R0 = 0,1,0
273 TA = 1;
274 T210 = 0;
275 R210 = 0x2;
276 ctrl1 = (1 << 7) | (TA << 6) | (T210 << 3) | R210;
277
278// ******** CHARGE PUMP CONFIG vs RF FREQUENCIES *****************
279 if (freq_khz < 470000)
280 cp210 = 2; // VHF Low and High band ch E12 to E4 to E12
281 else if (freq_khz < 526000)
282 cp210 = 4; // UHF band Ch E21 to E27
283 else // if (freq < 862000000)
284 cp210 = 5; // UHF band ch E28 to E69
285
286//********************* BW select *******************************
287 if (freq_khz < 153000)
288 p4321 = 1; // BW selected for VHF low
289 else if (freq_khz < 470000)
290 p4321 = 2; // BW selected for VHF high E5 to E12
291 else // if (freq < 862000000)
292 p4321 = 4; // BW selection for UHF E21 to E69
293
294 pllbuf[0] = (tfreq >> 8) & 0xff;
295 pllbuf[1] = (tfreq >> 0) & 0xff;
296 pllbuf[2] = 0xff & ctrl1;
297 pllbuf[3] = (cp210 << 5) | (p4321);
298
299 return 0;
300}
301
302/*
303 * 7 6 5 4 3 2 1 0
304 * Address Byte 1 1 0 0 0 MA1 MA0 R/~W=0
305 *
306 * Program divider byte 1 0 n14 n13 n12 n11 n10 n9 n8
307 * Program divider byte 2 n7 n6 n5 n4 n3 n2 n1 n0
308 *
309 * Control byte 1 1 T/A=1 T2 T1 T0 R2 R1 R0
310 * 1 T/A=0 0 0 ATC AL2 AL1 AL0
311 *
312 * Control byte 2 CP2 CP1 CP0 BS5 BS4 BS3 BS2 BS1
313 *
314 * MA0/1 = programmable address bits
315 * R/~W = read/write bit (0 for writing)
316 * N14-0 = programmable LO frequency
317 *
318 * T/A = test AGC bit (0 = next 6 bits AGC setting,
319 * 1 = next 6 bits test and reference divider ratio settings)
320 * T2-0 = test bits
321 * R2-0 = reference divider ratio and programmable frequency step
322 * ATC = AGC current setting and time constant
323 * ATC = 0: AGC current = 220nA, AGC time constant = 2s
324 * ATC = 1: AGC current = 9uA, AGC time constant = 50ms
325 * AL2-0 = AGC take-over point bits
326 * CP2-0 = charge pump current
327 * BS5-1 = PMOS ports control bits;
328 * BSn = 0 corresponding port is off, high-impedance state (at power-on)
329 * BSn = 1 corresponding port is on
330 */
331static int panasonic_cofdm_env77h11d5_tda6650_init(struct dvb_frontend *fe, u8 pllbuf[4])
332{
333 pllbuf[0] = 0x0b;
334 pllbuf[1] = 0xf5;
335 pllbuf[2] = 0x85;
336 pllbuf[3] = 0xab;
337 return 0;
338}
339
340static int panasonic_cofdm_env77h11d5_tda6650_set (struct dvb_frontend_parameters *fep,u8 pllbuf[4])
341{
342 int tuner_frequency = 0;
343 u8 band, cp, filter;
344
345 // determine charge pump
346 tuner_frequency = fep->frequency + 36166000;
347 if (tuner_frequency < 87000000)
348 return -EINVAL;
349 else if (tuner_frequency < 130000000)
350 cp = 3;
351 else if (tuner_frequency < 160000000)
352 cp = 5;
353 else if (tuner_frequency < 200000000)
354 cp = 6;
355 else if (tuner_frequency < 290000000)
356 cp = 3;
357 else if (tuner_frequency < 420000000)
358 cp = 5;
359 else if (tuner_frequency < 480000000)
360 cp = 6;
361 else if (tuner_frequency < 620000000)
362 cp = 3;
363 else if (tuner_frequency < 830000000)
364 cp = 5;
365 else if (tuner_frequency < 895000000)
366 cp = 7;
367 else
368 return -EINVAL;
369
370 // determine band
371 if (fep->frequency < 49000000)
372 return -EINVAL;
373 else if (fep->frequency < 161000000)
374 band = 1;
375 else if (fep->frequency < 444000000)
376 band = 2;
377 else if (fep->frequency < 861000000)
378 band = 4;
379 else
380 return -EINVAL;
381
382 // setup PLL filter
383 switch (fep->u.ofdm.bandwidth) {
384 case BANDWIDTH_6_MHZ:
385 case BANDWIDTH_7_MHZ:
386 filter = 0;
387 break;
388 case BANDWIDTH_8_MHZ:
389 filter = 1;
390 break;
391 default:
392 return -EINVAL;
393 }
394
395 // calculate divisor
396 // ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
397 tuner_frequency = (((fep->frequency / 1000) * 6) + 217496) / 1000;
398
399 // setup tuner buffer
400 pllbuf[0] = (tuner_frequency >> 8) & 0x7f;
401 pllbuf[1] = tuner_frequency & 0xff;
402 pllbuf[2] = 0xca;
403 pllbuf[3] = (cp << 5) | (filter << 3) | band;
404 return 0;
405}
406
407/*
408 * 7 6 5 4 3 2 1 0
409 * Address Byte 1 1 0 0 0 MA1 MA0 R/~W=0
410 *
411 * Program divider byte 1 0 n14 n13 n12 n11 n10 n9 n8
412 * Program divider byte 2 n7 n6 n5 n4 n3 n2 n1 n0
413 *
414 * Control byte 1 CP T2 T1 T0 RSA RSB OS
415 *
416 * Band Switch byte X X X P4 P3 P2 P1 P0
417 *
418 * Auxiliary byte ATC AL2 AL1 AL0 0 0 0 0
419 *
420 * Address: MA1 MA0 Address
421 * 0 0 c0
422 * 0 1 c2 (always valid)
423 * 1 0 c4
424 * 1 1 c6
425 */
426static int lg_tdtp_e102p_tua6034(struct dvb_frontend_parameters* fep, u8 pllbuf[4])
427{
428 u32 div;
429 u8 p210, p3;
430
431#define TUNER_MUL 62500
432
433 div = (fep->frequency + 36125000 + TUNER_MUL / 2) / TUNER_MUL;
434// div = ((fep->frequency/1000 + 36166) * 6) / 1000;
435
436 if (fep->frequency < 174500000)
437 p210 = 1; // not supported by the tdtp_e102p
438 else if (fep->frequency < 230000000) // VHF
439 p210 = 2;
440 else
441 p210 = 4;
442
443 if (fep->u.ofdm.bandwidth == BANDWIDTH_7_MHZ)
444 p3 = 0;
445 else
446 p3 = 1;
447
448 pllbuf[0] = (div >> 8) & 0x7f;
449 pllbuf[1] = div & 0xff;
450 pllbuf[2] = 0xce;
451// pllbuf[2] = 0xcc;
452 pllbuf[3] = (p3 << 3) | p210;
453
454 return 0;
455}
456
457static int lg_tdtp_e102p_mt352_demod_init(struct dvb_frontend *fe)
458{
459 static u8 mt352_clock_config[] = { 0x89, 0xb8, 0x2d };
460 static u8 mt352_reset[] = { 0x50, 0x80 };
461 static u8 mt352_mclk_ratio[] = { 0x8b, 0x00 };
462 static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0x40 };
463 static u8 mt352_agc_cfg[] = { 0x67, 0x10, 0xa0 };
464
465 static u8 mt352_sec_agc_cfg1[] = { 0x6a, 0xff };
466 static u8 mt352_sec_agc_cfg2[] = { 0x6d, 0xff };
467 static u8 mt352_sec_agc_cfg3[] = { 0x70, 0x40 };
468 static u8 mt352_sec_agc_cfg4[] = { 0x7b, 0x03 };
469 static u8 mt352_sec_agc_cfg5[] = { 0x7d, 0x0f };
470
471 static u8 mt352_acq_ctl[] = { 0x53, 0x50 };
472 static u8 mt352_input_freq_1[] = { 0x56, 0x31, 0x06 };
473
474 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
475 udelay(2000);
476 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
477 mt352_write(fe, mt352_mclk_ratio, sizeof(mt352_mclk_ratio));
478
479 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
480 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
481
482 mt352_write(fe, mt352_sec_agc_cfg1, sizeof(mt352_sec_agc_cfg1));
483 mt352_write(fe, mt352_sec_agc_cfg2, sizeof(mt352_sec_agc_cfg2));
484 mt352_write(fe, mt352_sec_agc_cfg3, sizeof(mt352_sec_agc_cfg3));
485 mt352_write(fe, mt352_sec_agc_cfg4, sizeof(mt352_sec_agc_cfg4));
486 mt352_write(fe, mt352_sec_agc_cfg5, sizeof(mt352_sec_agc_cfg5));
487
488 mt352_write(fe, mt352_acq_ctl, sizeof(mt352_acq_ctl));
489 mt352_write(fe, mt352_input_freq_1, sizeof(mt352_input_freq_1));
490
491 return 0;
492}
493
494static int dibusb_general_demod_init(struct dvb_frontend *fe)
495{
496 struct usb_dibusb* dib = (struct usb_dibusb*) fe->dvb->priv;
497 switch (dib->dibdev->dev_cl->id) {
498 case UMT2_0:
499 return lg_tdtp_e102p_mt352_demod_init(fe);
500 default: /* other device classes do not have device specific demod inits */
501 break;
502 }
503 return 0;
504}
505
506static u8 dibusb_general_pll_addr(struct dvb_frontend *fe)
507{
508 struct usb_dibusb* dib = (struct usb_dibusb*) fe->dvb->priv;
509 return dib->tuner->pll_addr;
510}
511
512static int dibusb_pll_i2c_helper(struct usb_dibusb *dib, u8 pll_buf[5], u8 buf[4])
513{
514 if (pll_buf == NULL) {
515 struct i2c_msg msg = {
516 .addr = dib->tuner->pll_addr,
517 .flags = 0,
518 .buf = buf,
519 .len = sizeof(buf)
520 };
521 if (i2c_transfer (&dib->i2c_adap, &msg, 1) != 1)
522 return -EIO;
523 msleep(1);
524 } else {
525 pll_buf[0] = dib->tuner->pll_addr << 1;
526 memcpy(&pll_buf[1],buf,4);
527 }
528
529 return 0;
530}
531
532static int dibusb_general_pll_init(struct dvb_frontend *fe,
533 u8 pll_buf[5])
534{
535 struct usb_dibusb* dib = (struct usb_dibusb*) fe->dvb->priv;
536 u8 buf[4];
537 int ret=0;
538 switch (dib->tuner->id) {
539 case DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5:
540 ret = panasonic_cofdm_env77h11d5_tda6650_init(fe,buf);
541 break;
542 default:
543 break;
544 }
545
546 if (ret)
547 return ret;
548
549 return dibusb_pll_i2c_helper(dib,pll_buf,buf);
550}
551
552static int dibusb_general_pll_set(struct dvb_frontend *fe,
553 struct dvb_frontend_parameters *fep, u8 pll_buf[5])
554{
555 struct usb_dibusb* dib = (struct usb_dibusb*) fe->dvb->priv;
556 u8 buf[4];
557 int ret=0;
558
559 switch (dib->tuner->id) {
560 case DIBUSB_TUNER_CABLE_THOMSON:
561 ret = thomson_cable_eu_pll_set(fep, buf);
562 break;
563 case DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5:
564 ret = panasonic_cofdm_env57h1xd5_pll_set(fep, buf);
565 break;
566 case DIBUSB_TUNER_CABLE_LG_TDTP_E102P:
567 ret = lg_tdtp_e102p_tua6034(fep, buf);
568 break;
569 case DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5:
570 ret = panasonic_cofdm_env77h11d5_tda6650_set(fep,buf);
571 break;
572 default:
573 warn("no pll programming routine found for tuner %d.\n",dib->tuner->id);
574 ret = -ENODEV;
575 break;
576 }
577
578 if (ret)
579 return ret;
580
581 return dibusb_pll_i2c_helper(dib,pll_buf,buf);
582}
diff --git a/drivers/media/dvb/dibusb/dvb-dibusb-firmware.c b/drivers/media/dvb/dibusb/dvb-dibusb-firmware.c
deleted file mode 100644
index 504ba47afdf3..000000000000
--- a/drivers/media/dvb/dibusb/dvb-dibusb-firmware.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * dvb-dibusb-firmware.c is part of the driver for mobile USB Budget DVB-T devices
3 * based on reference design made by DiBcom (http://www.dibcom.fr/)
4 *
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 *
7 * see dvb-dibusb-core.c for more copyright details.
8 *
9 * This file contains functions for downloading the firmware to the device.
10 */
11#include "dvb-dibusb.h"
12
13#include <linux/firmware.h>
14#include <linux/usb.h>
15
16/*
17 * load a firmware packet to the device
18 */
19static int dibusb_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 len)
20{
21 return usb_control_msg(udev, usb_sndctrlpipe(udev,0),
22 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5000);
23}
24
25int dibusb_loadfirmware(struct usb_device *udev, struct dibusb_usb_device *dibdev)
26{
27 const struct firmware *fw = NULL;
28 u16 addr;
29 u8 *b,*p;
30 int ret = 0,i;
31
32 if ((ret = request_firmware(&fw, dibdev->dev_cl->firmware, &udev->dev)) != 0) {
33 err("did not find the firmware file. (%s) "
34 "Please see linux/Documentation/dvb/ for more details on firmware-problems.",
35 dibdev->dev_cl->firmware);
36 return ret;
37 }
38
39 info("downloading firmware from file '%s'.",dibdev->dev_cl->firmware);
40
41 p = kmalloc(fw->size,GFP_KERNEL);
42 if (p != NULL) {
43 u8 reset;
44 /*
45 * you cannot use the fw->data as buffer for
46 * usb_control_msg, a new buffer has to be
47 * created
48 */
49 memcpy(p,fw->data,fw->size);
50
51 /* stop the CPU */
52 reset = 1;
53 if ((ret = dibusb_writemem(udev,dibdev->dev_cl->usb_ctrl->cpu_cs_register,&reset,1)) != 1)
54 err("could not stop the USB controller CPU.");
55 for(i = 0; p[i+3] == 0 && i < fw->size; ) {
56 b = (u8 *) &p[i];
57 addr = *((u16 *) &b[1]);
58
59 ret = dibusb_writemem(udev,addr,&b[4],b[0]);
60
61 if (ret != b[0]) {
62 err("error while transferring firmware "
63 "(transferred size: %d, block size: %d)",
64 ret,b[0]);
65 ret = -EINVAL;
66 break;
67 }
68 i += 5 + b[0];
69 }
70 /* length in ret */
71 if (ret > 0)
72 ret = 0;
73 /* restart the CPU */
74 reset = 0;
75 if (ret || dibusb_writemem(udev,dibdev->dev_cl->usb_ctrl->cpu_cs_register,&reset,1) != 1) {
76 err("could not restart the USB controller CPU.");
77 ret = -EINVAL;
78 }
79
80 kfree(p);
81 } else {
82 ret = -ENOMEM;
83 }
84 release_firmware(fw);
85
86 return ret;
87}
diff --git a/drivers/media/dvb/dibusb/dvb-dibusb-remote.c b/drivers/media/dvb/dibusb/dvb-dibusb-remote.c
deleted file mode 100644
index 9dc8b15517b7..000000000000
--- a/drivers/media/dvb/dibusb/dvb-dibusb-remote.c
+++ /dev/null
@@ -1,316 +0,0 @@
1/*
2 * dvb-dibusb-remote.c is part of the driver for mobile USB Budget DVB-T devices
3 * based on reference design made by DiBcom (http://www.dibcom.fr/)
4 *
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 *
7 * see dvb-dibusb-core.c for more copyright details.
8 *
9 * This file contains functions for handling the event device on the software
10 * side and the remote control on the hardware side.
11 */
12#include "dvb-dibusb.h"
13
14/* Table to map raw key codes to key events. This should not be hard-wired
15 into the kernel. */
16static const struct { u8 c0, c1, c2; uint32_t key; } nec_rc_keys [] =
17{
18 /* Key codes for the little Artec T1/Twinhan/HAMA/ remote. */
19 { 0x00, 0xff, 0x16, KEY_POWER },
20 { 0x00, 0xff, 0x10, KEY_MUTE },
21 { 0x00, 0xff, 0x03, KEY_1 },
22 { 0x00, 0xff, 0x01, KEY_2 },
23 { 0x00, 0xff, 0x06, KEY_3 },
24 { 0x00, 0xff, 0x09, KEY_4 },
25 { 0x00, 0xff, 0x1d, KEY_5 },
26 { 0x00, 0xff, 0x1f, KEY_6 },
27 { 0x00, 0xff, 0x0d, KEY_7 },
28 { 0x00, 0xff, 0x19, KEY_8 },
29 { 0x00, 0xff, 0x1b, KEY_9 },
30 { 0x00, 0xff, 0x15, KEY_0 },
31 { 0x00, 0xff, 0x05, KEY_CHANNELUP },
32 { 0x00, 0xff, 0x02, KEY_CHANNELDOWN },
33 { 0x00, 0xff, 0x1e, KEY_VOLUMEUP },
34 { 0x00, 0xff, 0x0a, KEY_VOLUMEDOWN },
35 { 0x00, 0xff, 0x11, KEY_RECORD },
36 { 0x00, 0xff, 0x17, KEY_FAVORITES }, /* Heart symbol - Channel list. */
37 { 0x00, 0xff, 0x14, KEY_PLAY },
38 { 0x00, 0xff, 0x1a, KEY_STOP },
39 { 0x00, 0xff, 0x40, KEY_REWIND },
40 { 0x00, 0xff, 0x12, KEY_FASTFORWARD },
41 { 0x00, 0xff, 0x0e, KEY_PREVIOUS }, /* Recall - Previous channel. */
42 { 0x00, 0xff, 0x4c, KEY_PAUSE },
43 { 0x00, 0xff, 0x4d, KEY_SCREEN }, /* Full screen mode. */
44 { 0x00, 0xff, 0x54, KEY_AUDIO }, /* MTS - Switch to secondary audio. */
45 /* additional keys TwinHan VisionPlus, the Artec seemingly not have */
46 { 0x00, 0xff, 0x0c, KEY_CANCEL }, /* Cancel */
47 { 0x00, 0xff, 0x1c, KEY_EPG }, /* EPG */
48 { 0x00, 0xff, 0x00, KEY_TAB }, /* Tab */
49 { 0x00, 0xff, 0x48, KEY_INFO }, /* Preview */
50 { 0x00, 0xff, 0x04, KEY_LIST }, /* RecordList */
51 { 0x00, 0xff, 0x0f, KEY_TEXT }, /* Teletext */
52 /* Key codes for the KWorld/ADSTech/JetWay remote. */
53 { 0x86, 0x6b, 0x12, KEY_POWER },
54 { 0x86, 0x6b, 0x0f, KEY_SELECT }, /* source */
55 { 0x86, 0x6b, 0x0c, KEY_UNKNOWN }, /* scan */
56 { 0x86, 0x6b, 0x0b, KEY_EPG },
57 { 0x86, 0x6b, 0x10, KEY_MUTE },
58 { 0x86, 0x6b, 0x01, KEY_1 },
59 { 0x86, 0x6b, 0x02, KEY_2 },
60 { 0x86, 0x6b, 0x03, KEY_3 },
61 { 0x86, 0x6b, 0x04, KEY_4 },
62 { 0x86, 0x6b, 0x05, KEY_5 },
63 { 0x86, 0x6b, 0x06, KEY_6 },
64 { 0x86, 0x6b, 0x07, KEY_7 },
65 { 0x86, 0x6b, 0x08, KEY_8 },
66 { 0x86, 0x6b, 0x09, KEY_9 },
67 { 0x86, 0x6b, 0x0a, KEY_0 },
68 { 0x86, 0x6b, 0x18, KEY_ZOOM },
69 { 0x86, 0x6b, 0x1c, KEY_UNKNOWN }, /* preview */
70 { 0x86, 0x6b, 0x13, KEY_UNKNOWN }, /* snap */
71 { 0x86, 0x6b, 0x00, KEY_UNDO },
72 { 0x86, 0x6b, 0x1d, KEY_RECORD },
73 { 0x86, 0x6b, 0x0d, KEY_STOP },
74 { 0x86, 0x6b, 0x0e, KEY_PAUSE },
75 { 0x86, 0x6b, 0x16, KEY_PLAY },
76 { 0x86, 0x6b, 0x11, KEY_BACK },
77 { 0x86, 0x6b, 0x19, KEY_FORWARD },
78 { 0x86, 0x6b, 0x14, KEY_UNKNOWN }, /* pip */
79 { 0x86, 0x6b, 0x15, KEY_ESC },
80 { 0x86, 0x6b, 0x1a, KEY_UP },
81 { 0x86, 0x6b, 0x1e, KEY_DOWN },
82 { 0x86, 0x6b, 0x1f, KEY_LEFT },
83 { 0x86, 0x6b, 0x1b, KEY_RIGHT },
84};
85
86/* Hauppauge NOVA-T USB2 keys */
87static const struct { u16 raw; uint32_t key; } haupp_rc_keys [] = {
88 { 0xddf, KEY_GOTO },
89 { 0xdef, KEY_POWER },
90 { 0xce7, KEY_TV },
91 { 0xcc7, KEY_VIDEO },
92 { 0xccf, KEY_AUDIO },
93 { 0xcd7, KEY_MEDIA },
94 { 0xcdf, KEY_EPG },
95 { 0xca7, KEY_UP },
96 { 0xc67, KEY_RADIO },
97 { 0xcb7, KEY_LEFT },
98 { 0xd2f, KEY_OK },
99 { 0xcbf, KEY_RIGHT },
100 { 0xcff, KEY_BACK },
101 { 0xcaf, KEY_DOWN },
102 { 0xc6f, KEY_MENU },
103 { 0xc87, KEY_VOLUMEUP },
104 { 0xc8f, KEY_VOLUMEDOWN },
105 { 0xc97, KEY_CHANNEL },
106 { 0xc7f, KEY_MUTE },
107 { 0xd07, KEY_CHANNELUP },
108 { 0xd0f, KEY_CHANNELDOWN },
109 { 0xdbf, KEY_RECORD },
110 { 0xdb7, KEY_STOP },
111 { 0xd97, KEY_REWIND },
112 { 0xdaf, KEY_PLAY },
113 { 0xda7, KEY_FASTFORWARD },
114 { 0xd27, KEY_LAST }, /* Skip backwards */
115 { 0xd87, KEY_PAUSE },
116 { 0xcf7, KEY_NEXT },
117 { 0xc07, KEY_0 },
118 { 0xc0f, KEY_1 },
119 { 0xc17, KEY_2 },
120 { 0xc1f, KEY_3 },
121 { 0xc27, KEY_4 },
122 { 0xc2f, KEY_5 },
123 { 0xc37, KEY_6 },
124 { 0xc3f, KEY_7 },
125 { 0xc47, KEY_8 },
126 { 0xc4f, KEY_9 },
127 { 0xc57, KEY_KPASTERISK },
128 { 0xc77, KEY_GRAVE }, /* # */
129 { 0xc5f, KEY_RED },
130 { 0xd77, KEY_GREEN },
131 { 0xdc7, KEY_YELLOW },
132 { 0xd4f, KEY_BLUE},
133};
134
135static int dibusb_key2event_nec(struct usb_dibusb *dib,u8 rb[5])
136{
137 int i;
138 switch (rb[0]) {
139 case DIBUSB_RC_NEC_KEY_PRESSED:
140 /* rb[1-3] is the actual key, rb[4] is a checksum */
141 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
142 rb[1], rb[2], rb[3], rb[4]);
143
144 if ((0xff - rb[3]) != rb[4]) {
145 deb_rc("remote control checksum failed.\n");
146 break;
147 }
148
149 /* See if we can match the raw key code. */
150 for (i = 0; i < sizeof(nec_rc_keys)/sizeof(nec_rc_keys[0]); i++) {
151 if (nec_rc_keys[i].c0 == rb[1] &&
152 nec_rc_keys[i].c1 == rb[2] &&
153 nec_rc_keys[i].c2 == rb[3]) {
154
155 dib->last_event = nec_rc_keys[i].key;
156 return 1;
157 }
158 }
159 break;
160 case DIBUSB_RC_NEC_KEY_REPEATED:
161 /* rb[1]..rb[4] are always zero.*/
162 /* Repeats often seem to occur so for the moment just ignore this. */
163 return 0;
164 case DIBUSB_RC_NEC_EMPTY: /* No (more) remote control keys. */
165 default:
166 break;
167 }
168 return -1;
169}
170
171static int dibusb_key2event_hauppauge(struct usb_dibusb *dib,u8 rb[4])
172{
173 u16 raw;
174 int i,state;
175 switch (rb[0]) {
176 case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
177 raw = ((rb[1] & 0x0f) << 8) | rb[2];
178
179 state = !!(rb[1] & 0x40);
180
181 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to %04x state: %d\n",rb[1],rb[2],rb[3],raw,state);
182 for (i = 0; i < sizeof(haupp_rc_keys)/sizeof(haupp_rc_keys[0]); i++) {
183 if (haupp_rc_keys[i].raw == raw) {
184 if (dib->last_event == haupp_rc_keys[i].key &&
185 dib->last_state == state) {
186 deb_rc("key repeat\n");
187 return 0;
188 } else {
189 dib->last_event = haupp_rc_keys[i].key;
190 dib->last_state = state;
191 return 1;
192 }
193 }
194 }
195
196 break;
197 case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
198 default:
199 break;
200 }
201 return -1;
202}
203
204/*
205 * Read the remote control and feed the appropriate event.
206 * NEC protocol is used for remote controls
207 */
208static int dibusb_read_remote_control(struct usb_dibusb *dib)
209{
210 u8 b[1] = { DIBUSB_REQ_POLL_REMOTE }, rb[5];
211 int ret,event = 0;
212
213 if ((ret = dibusb_readwrite_usb(dib,b,1,rb,5)))
214 return ret;
215
216 switch (dib->dibdev->dev_cl->remote_type) {
217 case DIBUSB_RC_NEC_PROTOCOL:
218 event = dibusb_key2event_nec(dib,rb);
219 break;
220 case DIBUSB_RC_HAUPPAUGE_PROTO:
221 event = dibusb_key2event_hauppauge(dib,rb);
222 default:
223 break;
224 }
225
226 /* key repeat */
227 if (event == 0)
228 if (++dib->repeat_key_count < dib->rc_key_repeat_count) {
229 deb_rc("key repeat dropped. (%d)\n",dib->repeat_key_count);
230 event = -1; /* skip this key repeat */
231 }
232
233 if (event == 1 || event == 0) {
234 deb_rc("Translated key 0x%04x\n",event);
235
236 /* Signal down and up events for this key. */
237 input_report_key(&dib->rc_input_dev, dib->last_event, 1);
238 input_report_key(&dib->rc_input_dev, dib->last_event, 0);
239 input_sync(&dib->rc_input_dev);
240
241 if (event == 1)
242 dib->repeat_key_count = 0;
243 }
244 return 0;
245}
246
247/* Remote-control poll function - called every dib->rc_query_interval ms to see
248 whether the remote control has received anything. */
249static void dibusb_remote_query(void *data)
250{
251 struct usb_dibusb *dib = (struct usb_dibusb *) data;
252 /* TODO: need a lock here. We can simply skip checking for the remote control
253 if we're busy. */
254 dibusb_read_remote_control(dib);
255 schedule_delayed_work(&dib->rc_query_work,
256 msecs_to_jiffies(dib->rc_query_interval));
257}
258
259int dibusb_remote_init(struct usb_dibusb *dib)
260{
261 int i;
262
263 if (dib->dibdev->dev_cl->remote_type == DIBUSB_RC_NO)
264 return 0;
265
266 /* Initialise the remote-control structures.*/
267 init_input_dev(&dib->rc_input_dev);
268
269 dib->rc_input_dev.evbit[0] = BIT(EV_KEY);
270 dib->rc_input_dev.keycodesize = sizeof(unsigned char);
271 dib->rc_input_dev.keycodemax = KEY_MAX;
272 dib->rc_input_dev.name = DRIVER_DESC " remote control";
273
274 switch (dib->dibdev->dev_cl->remote_type) {
275 case DIBUSB_RC_NEC_PROTOCOL:
276 for (i=0; i<sizeof(nec_rc_keys)/sizeof(nec_rc_keys[0]); i++)
277 set_bit(nec_rc_keys[i].key, dib->rc_input_dev.keybit);
278 break;
279 case DIBUSB_RC_HAUPPAUGE_PROTO:
280 for (i=0; i<sizeof(haupp_rc_keys)/sizeof(haupp_rc_keys[0]); i++)
281 set_bit(haupp_rc_keys[i].key, dib->rc_input_dev.keybit);
282 break;
283 default:
284 break;
285 }
286
287
288 input_register_device(&dib->rc_input_dev);
289
290 INIT_WORK(&dib->rc_query_work, dibusb_remote_query, dib);
291
292 /* Start the remote-control polling. */
293 if (dib->rc_query_interval < 40)
294 dib->rc_query_interval = 100; /* default */
295
296 info("schedule remote query interval to %d msecs.",dib->rc_query_interval);
297 schedule_delayed_work(&dib->rc_query_work,msecs_to_jiffies(dib->rc_query_interval));
298
299 dib->init_state |= DIBUSB_STATE_REMOTE;
300
301 return 0;
302}
303
304int dibusb_remote_exit(struct usb_dibusb *dib)
305{
306 if (dib->dibdev->dev_cl->remote_type == DIBUSB_RC_NO)
307 return 0;
308
309 if (dib->init_state & DIBUSB_STATE_REMOTE) {
310 cancel_delayed_work(&dib->rc_query_work);
311 flush_scheduled_work();
312 input_unregister_device(&dib->rc_input_dev);
313 }
314 dib->init_state &= ~DIBUSB_STATE_REMOTE;
315 return 0;
316}
diff --git a/drivers/media/dvb/dibusb/dvb-dibusb-usb.c b/drivers/media/dvb/dibusb/dvb-dibusb-usb.c
deleted file mode 100644
index 642f0596a5ba..000000000000
--- a/drivers/media/dvb/dibusb/dvb-dibusb-usb.c
+++ /dev/null
@@ -1,303 +0,0 @@
1/*
2 * dvb-dibusb-usb.c is part of the driver for mobile USB Budget DVB-T devices
3 * based on reference design made by DiBcom (http://www.dibcom.fr/)
4 *
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 *
7 * see dvb-dibusb-core.c for more copyright details.
8 *
9 * This file contains functions for initializing and handling the
10 * usb specific stuff.
11 */
12#include "dvb-dibusb.h"
13
14#include <linux/version.h>
15#include <linux/pci.h>
16
17int dibusb_readwrite_usb(struct usb_dibusb *dib, u8 *wbuf, u16 wlen, u8 *rbuf,
18 u16 rlen)
19{
20 int actlen,ret = -ENOMEM;
21
22 if (wbuf == NULL || wlen == 0)
23 return -EINVAL;
24
25 if ((ret = down_interruptible(&dib->usb_sem)))
26 return ret;
27
28 debug_dump(wbuf,wlen);
29
30 ret = usb_bulk_msg(dib->udev,usb_sndbulkpipe(dib->udev,
31 dib->dibdev->dev_cl->pipe_cmd), wbuf,wlen,&actlen,
32 DIBUSB_I2C_TIMEOUT);
33
34 if (ret)
35 err("bulk message failed: %d (%d/%d)",ret,wlen,actlen);
36 else
37 ret = actlen != wlen ? -1 : 0;
38
39 /* an answer is expected, and no error before */
40 if (!ret && rbuf && rlen) {
41 ret = usb_bulk_msg(dib->udev,usb_rcvbulkpipe(dib->udev,
42 dib->dibdev->dev_cl->pipe_cmd),rbuf,rlen,&actlen,
43 DIBUSB_I2C_TIMEOUT);
44
45 if (ret)
46 err("recv bulk message failed: %d",ret);
47 else {
48 deb_alot("rlen: %d\n",rlen);
49 debug_dump(rbuf,actlen);
50 }
51 }
52
53 up(&dib->usb_sem);
54 return ret;
55}
56
57/*
58 * Cypress controls
59 */
60int dibusb_write_usb(struct usb_dibusb *dib, u8 *buf, u16 len)
61{
62 return dibusb_readwrite_usb(dib,buf,len,NULL,0);
63}
64
65#if 0
66/*
67 * #if 0'ing the following functions as they are not in use _now_,
68 * but probably will be sometime.
69 */
70/*
71 * do not use this, just a workaround for a bug,
72 * which will hopefully never occur :).
73 */
74int dibusb_interrupt_read_loop(struct usb_dibusb *dib)
75{
76 u8 b[1] = { DIBUSB_REQ_INTR_READ };
77 return dibusb_write_usb(dib,b,1);
78}
79#endif
80
81/*
82 * ioctl for the firmware
83 */
84static int dibusb_ioctl_cmd(struct usb_dibusb *dib, u8 cmd, u8 *param, int plen)
85{
86 u8 b[34];
87 int size = plen > 32 ? 32 : plen;
88 memset(b,0,34);
89 b[0] = DIBUSB_REQ_SET_IOCTL;
90 b[1] = cmd;
91
92 if (size > 0)
93 memcpy(&b[2],param,size);
94
95 return dibusb_write_usb(dib,b,34); //2+size);
96}
97
98/*
99 * ioctl for power control
100 */
101int dibusb_hw_wakeup(struct dvb_frontend *fe)
102{
103 struct usb_dibusb *dib = (struct usb_dibusb *) fe->dvb->priv;
104 u8 b[1] = { DIBUSB_IOCTL_POWER_WAKEUP };
105 deb_info("dibusb-device is getting up.\n");
106
107 switch (dib->dibdev->dev_cl->id) {
108 case DTT200U:
109 break;
110 default:
111 dibusb_ioctl_cmd(dib,DIBUSB_IOCTL_CMD_POWER_MODE, b,1);
112 break;
113 }
114
115 if (dib->fe_init)
116 return dib->fe_init(fe);
117
118 return 0;
119}
120
121int dibusb_hw_sleep(struct dvb_frontend *fe)
122{
123 struct usb_dibusb *dib = (struct usb_dibusb *) fe->dvb->priv;
124 u8 b[1] = { DIBUSB_IOCTL_POWER_SLEEP };
125 deb_info("dibusb-device is going to bed.\n");
126 /* workaround, something is wrong, when dibusb 1.1 device are going to bed too late */
127 switch (dib->dibdev->dev_cl->id) {
128 case DIBUSB1_1:
129 case NOVAT_USB2:
130 case DTT200U:
131 break;
132 default:
133 dibusb_ioctl_cmd(dib,DIBUSB_IOCTL_CMD_POWER_MODE, b,1);
134 break;
135 }
136 if (dib->fe_sleep)
137 return dib->fe_sleep(fe);
138
139 return 0;
140}
141
142int dibusb_set_streaming_mode(struct usb_dibusb *dib,u8 mode)
143{
144 u8 b[2] = { DIBUSB_REQ_SET_STREAMING_MODE, mode };
145 return dibusb_readwrite_usb(dib,b,2,NULL,0);
146}
147
148static int dibusb_urb_kill(struct usb_dibusb *dib)
149{
150 int i;
151deb_info("trying to kill urbs\n");
152 if (dib->init_state & DIBUSB_STATE_URB_SUBMIT) {
153 for (i = 0; i < dib->dibdev->dev_cl->urb_count; i++) {
154 deb_info("killing URB no. %d.\n",i);
155
156 /* stop the URB */
157 usb_kill_urb(dib->urb_list[i]);
158 }
159 } else
160 deb_info(" URBs not killed.\n");
161 dib->init_state &= ~DIBUSB_STATE_URB_SUBMIT;
162 return 0;
163}
164
165static int dibusb_urb_submit(struct usb_dibusb *dib)
166{
167 int i,ret;
168 if (dib->init_state & DIBUSB_STATE_URB_INIT) {
169 for (i = 0; i < dib->dibdev->dev_cl->urb_count; i++) {
170 deb_info("submitting URB no. %d\n",i);
171 if ((ret = usb_submit_urb(dib->urb_list[i],GFP_ATOMIC))) {
172 err("could not submit buffer urb no. %d - get them all back\n",i);
173 dibusb_urb_kill(dib);
174 return ret;
175 }
176 dib->init_state |= DIBUSB_STATE_URB_SUBMIT;
177 }
178 }
179 return 0;
180}
181
182int dibusb_streaming(struct usb_dibusb *dib,int onoff)
183{
184 if (onoff)
185 dibusb_urb_submit(dib);
186 else
187 dibusb_urb_kill(dib);
188
189 switch (dib->dibdev->dev_cl->id) {
190 case DIBUSB2_0:
191 case DIBUSB2_0B:
192 case NOVAT_USB2:
193 case UMT2_0:
194 if (onoff)
195 return dibusb_ioctl_cmd(dib,DIBUSB_IOCTL_CMD_ENABLE_STREAM,NULL,0);
196 else
197 return dibusb_ioctl_cmd(dib,DIBUSB_IOCTL_CMD_DISABLE_STREAM,NULL,0);
198 break;
199 default:
200 break;
201 }
202 return 0;
203}
204
205int dibusb_urb_init(struct usb_dibusb *dib)
206{
207 int i,bufsize,def_pid_parse = 1;
208
209 /*
210 * when reloading the driver w/o replugging the device
211 * a timeout occures, this helps
212 */
213 usb_clear_halt(dib->udev,usb_sndbulkpipe(dib->udev,dib->dibdev->dev_cl->pipe_cmd));
214 usb_clear_halt(dib->udev,usb_rcvbulkpipe(dib->udev,dib->dibdev->dev_cl->pipe_cmd));
215 usb_clear_halt(dib->udev,usb_rcvbulkpipe(dib->udev,dib->dibdev->dev_cl->pipe_data));
216
217 /* allocate the array for the data transfer URBs */
218 dib->urb_list = kmalloc(dib->dibdev->dev_cl->urb_count*sizeof(struct urb *),GFP_KERNEL);
219 if (dib->urb_list == NULL)
220 return -ENOMEM;
221 memset(dib->urb_list,0,dib->dibdev->dev_cl->urb_count*sizeof(struct urb *));
222
223 dib->init_state |= DIBUSB_STATE_URB_LIST;
224
225 bufsize = dib->dibdev->dev_cl->urb_count*dib->dibdev->dev_cl->urb_buffer_size;
226 deb_info("allocate %d bytes as buffersize for all URBs\n",bufsize);
227 /* allocate the actual buffer for the URBs */
228 if ((dib->buffer = pci_alloc_consistent(NULL,bufsize,&dib->dma_handle)) == NULL) {
229 deb_info("not enough memory.\n");
230 return -ENOMEM;
231 }
232 deb_info("allocation complete\n");
233 memset(dib->buffer,0,bufsize);
234
235 dib->init_state |= DIBUSB_STATE_URB_BUF;
236
237 /* allocate and submit the URBs */
238 for (i = 0; i < dib->dibdev->dev_cl->urb_count; i++) {
239 if (!(dib->urb_list[i] = usb_alloc_urb(0,GFP_ATOMIC))) {
240 return -ENOMEM;
241 }
242
243 usb_fill_bulk_urb( dib->urb_list[i], dib->udev,
244 usb_rcvbulkpipe(dib->udev,dib->dibdev->dev_cl->pipe_data),
245 &dib->buffer[i*dib->dibdev->dev_cl->urb_buffer_size],
246 dib->dibdev->dev_cl->urb_buffer_size,
247 dibusb_urb_complete, dib);
248
249 dib->urb_list[i]->transfer_flags = 0;
250
251 dib->init_state |= DIBUSB_STATE_URB_INIT;
252 }
253
254 /* dib->pid_parse here contains the value of the module parameter */
255 /* decide if pid parsing can be deactivated:
256 * is possible (by device type) and wanted (by user)
257 */
258 switch (dib->dibdev->dev_cl->id) {
259 case DIBUSB2_0:
260 case DIBUSB2_0B:
261 if (dib->udev->speed == USB_SPEED_HIGH && !dib->pid_parse) {
262 def_pid_parse = 0;
263 info("running at HIGH speed, will deliver the complete TS.");
264 } else
265 info("will use pid_parsing.");
266 break;
267 default:
268 break;
269 }
270 /* from here on it contains the device and user decision */
271 dib->pid_parse = def_pid_parse;
272
273 return 0;
274}
275
276int dibusb_urb_exit(struct usb_dibusb *dib)
277{
278 int i;
279
280 dibusb_urb_kill(dib);
281
282 if (dib->init_state & DIBUSB_STATE_URB_LIST) {
283 for (i = 0; i < dib->dibdev->dev_cl->urb_count; i++) {
284 if (dib->urb_list[i] != NULL) {
285 deb_info("freeing URB no. %d.\n",i);
286 /* free the URBs */
287 usb_free_urb(dib->urb_list[i]);
288 }
289 }
290 /* free the urb array */
291 kfree(dib->urb_list);
292 dib->init_state &= ~DIBUSB_STATE_URB_LIST;
293 }
294
295 if (dib->init_state & DIBUSB_STATE_URB_BUF)
296 pci_free_consistent(NULL,
297 dib->dibdev->dev_cl->urb_buffer_size*dib->dibdev->dev_cl->urb_count,
298 dib->buffer,dib->dma_handle);
299
300 dib->init_state &= ~DIBUSB_STATE_URB_BUF;
301 dib->init_state &= ~DIBUSB_STATE_URB_INIT;
302 return 0;
303}
diff --git a/drivers/media/dvb/dibusb/dvb-dibusb.h b/drivers/media/dvb/dibusb/dvb-dibusb.h
deleted file mode 100644
index 52cd35dd9d83..000000000000
--- a/drivers/media/dvb/dibusb/dvb-dibusb.h
+++ /dev/null
@@ -1,327 +0,0 @@
1/*
2 * dvb-dibusb.h
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 * for more information see dvb-dibusb-core.c .
11 */
12#ifndef __DVB_DIBUSB_H__
13#define __DVB_DIBUSB_H__
14
15#include <linux/input.h>
16#include <linux/config.h>
17#include <linux/usb.h>
18
19#include "dvb_frontend.h"
20#include "dvb_demux.h"
21#include "dvb_net.h"
22#include "dmxdev.h"
23
24#include "dib3000.h"
25#include "mt352.h"
26
27/* debug */
28#ifdef CONFIG_DVB_DIBCOM_DEBUG
29#define dprintk(level,args...) \
30 do { if ((dvb_dibusb_debug & level)) { printk(args); } } while (0)
31
32#define debug_dump(b,l) {\
33 int i; \
34 for (i = 0; i < l; i++) deb_xfer("%02x ", b[i]); \
35 deb_xfer("\n");\
36}
37
38#else
39#define dprintk(args...)
40#define debug_dump(b,l)
41#endif
42
43extern int dvb_dibusb_debug;
44
45/* Version information */
46#define DRIVER_VERSION "0.3"
47#define DRIVER_DESC "DiBcom based USB Budget DVB-T device"
48#define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
49
50#define deb_info(args...) dprintk(0x01,args)
51#define deb_xfer(args...) dprintk(0x02,args)
52#define deb_alot(args...) dprintk(0x04,args)
53#define deb_ts(args...) dprintk(0x08,args)
54#define deb_err(args...) dprintk(0x10,args)
55#define deb_rc(args...) dprintk(0x20,args)
56
57/* generic log methods - taken from usb.h */
58#undef err
59#define err(format, arg...) printk(KERN_ERR "dvb-dibusb: " format "\n" , ## arg)
60#undef info
61#define info(format, arg...) printk(KERN_INFO "dvb-dibusb: " format "\n" , ## arg)
62#undef warn
63#define warn(format, arg...) printk(KERN_WARNING "dvb-dibusb: " format "\n" , ## arg)
64
65struct dibusb_usb_controller {
66 const char *name; /* name of the usb controller */
67 u16 cpu_cs_register; /* needs to be restarted, when the firmware has been downloaded. */
68};
69
70typedef enum {
71 DIBUSB1_1 = 0,
72 DIBUSB1_1_AN2235,
73 DIBUSB2_0,
74 UMT2_0,
75 DIBUSB2_0B,
76 NOVAT_USB2,
77 DTT200U,
78} dibusb_class_t;
79
80typedef enum {
81 DIBUSB_TUNER_CABLE_THOMSON = 0,
82 DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5,
83 DIBUSB_TUNER_CABLE_LG_TDTP_E102P,
84 DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5,
85} dibusb_tuner_t;
86
87typedef enum {
88 DIBUSB_DIB3000MB = 0,
89 DIBUSB_DIB3000MC,
90 DIBUSB_MT352,
91 DTT200U_FE,
92} dibusb_demodulator_t;
93
94typedef enum {
95 DIBUSB_RC_NO = 0,
96 DIBUSB_RC_NEC_PROTOCOL,
97 DIBUSB_RC_HAUPPAUGE_PROTO,
98} dibusb_remote_t;
99
100struct dibusb_tuner {
101 dibusb_tuner_t id;
102
103 u8 pll_addr; /* tuner i2c address */
104};
105extern struct dibusb_tuner dibusb_tuner[];
106
107#define DIBUSB_POSSIBLE_I2C_ADDR_NUM 4
108struct dibusb_demod {
109 dibusb_demodulator_t id;
110
111 int pid_filter_count; /* counter of the internal pid_filter */
112 u8 i2c_addrs[DIBUSB_POSSIBLE_I2C_ADDR_NUM]; /* list of possible i2c addresses of the demod */
113};
114
115#define DIBUSB_MAX_TUNER_NUM 2
116struct dibusb_device_class {
117 dibusb_class_t id;
118
119 const struct dibusb_usb_controller *usb_ctrl; /* usb controller */
120 const char *firmware; /* valid firmware filenames */
121
122 int pipe_cmd; /* command pipe (read/write) */
123 int pipe_data; /* data pipe */
124
125 int urb_count; /* number of data URBs to be submitted */
126 int urb_buffer_size; /* the size of the buffer for each URB */
127
128 dibusb_remote_t remote_type; /* does this device have a ir-receiver */
129
130 struct dibusb_demod *demod; /* which demodulator is mount */
131 struct dibusb_tuner *tuner; /* which tuner can be found here */
132};
133
134#define DIBUSB_ID_MAX_NUM 15
135struct dibusb_usb_device {
136 const char *name; /* real name of the box */
137 struct dibusb_device_class *dev_cl; /* which dibusb_device_class is this device part of */
138
139 struct usb_device_id *cold_ids[DIBUSB_ID_MAX_NUM]; /* list of USB ids when this device is at pre firmware state */
140 struct usb_device_id *warm_ids[DIBUSB_ID_MAX_NUM]; /* list of USB ids when this device is at post firmware state */
141};
142
143/* a PID for the pid_filter list, when in use */
144struct dibusb_pid
145{
146 int index;
147 u16 pid;
148 int active;
149};
150
151struct usb_dibusb {
152 /* usb */
153 struct usb_device * udev;
154
155 struct dibusb_usb_device * dibdev;
156
157#define DIBUSB_STATE_INIT 0x000
158#define DIBUSB_STATE_URB_LIST 0x001
159#define DIBUSB_STATE_URB_BUF 0x002
160#define DIBUSB_STATE_URB_INIT 0x004
161#define DIBUSB_STATE_DVB 0x008
162#define DIBUSB_STATE_I2C 0x010
163#define DIBUSB_STATE_REMOTE 0x020
164#define DIBUSB_STATE_URB_SUBMIT 0x040
165 int init_state;
166
167 int feedcount;
168 struct dib_fe_xfer_ops xfer_ops;
169
170 struct dibusb_tuner *tuner;
171
172 struct urb **urb_list;
173 u8 *buffer;
174 dma_addr_t dma_handle;
175
176 /* I2C */
177 struct i2c_adapter i2c_adap;
178
179 /* locking */
180 struct semaphore usb_sem;
181 struct semaphore i2c_sem;
182
183 /* dvb */
184 struct dvb_adapter *adapter;
185 struct dmxdev dmxdev;
186 struct dvb_demux demux;
187 struct dvb_net dvb_net;
188 struct dvb_frontend* fe;
189
190 int (*fe_sleep) (struct dvb_frontend *);
191 int (*fe_init) (struct dvb_frontend *);
192
193 /* remote control */
194 struct input_dev rc_input_dev;
195 struct work_struct rc_query_work;
196 int last_event;
197 int last_state; /* for Hauppauge RC protocol */
198 int repeat_key_count;
199 int rc_key_repeat_count; /* module parameter */
200
201 /* module parameters */
202 int pid_parse;
203 int rc_query_interval;
204};
205
206/* commonly used functions in the separated files */
207
208/* dvb-dibusb-firmware.c */
209int dibusb_loadfirmware(struct usb_device *udev, struct dibusb_usb_device *dibdev);
210
211/* dvb-dibusb-remote.c */
212int dibusb_remote_exit(struct usb_dibusb *dib);
213int dibusb_remote_init(struct usb_dibusb *dib);
214
215/* dvb-dibusb-fe-i2c.c */
216int dibusb_fe_init(struct usb_dibusb* dib);
217int dibusb_fe_exit(struct usb_dibusb *dib);
218int dibusb_i2c_init(struct usb_dibusb *dib);
219int dibusb_i2c_exit(struct usb_dibusb *dib);
220
221/* dvb-dibusb-dvb.c */
222void dibusb_urb_complete(struct urb *urb, struct pt_regs *ptregs);
223int dibusb_dvb_init(struct usb_dibusb *dib);
224int dibusb_dvb_exit(struct usb_dibusb *dib);
225
226/* dvb-dibusb-usb.c */
227int dibusb_readwrite_usb(struct usb_dibusb *dib, u8 *wbuf, u16 wlen, u8 *rbuf,
228 u16 rlen);
229int dibusb_write_usb(struct usb_dibusb *dib, u8 *buf, u16 len);
230
231int dibusb_hw_wakeup(struct dvb_frontend *);
232int dibusb_hw_sleep(struct dvb_frontend *);
233int dibusb_set_streaming_mode(struct usb_dibusb *,u8);
234int dibusb_streaming(struct usb_dibusb *,int);
235
236int dibusb_urb_init(struct usb_dibusb *);
237int dibusb_urb_exit(struct usb_dibusb *);
238
239/* dvb-fe-dtt200u.c */
240struct dvb_frontend* dtt200u_fe_attach(struct usb_dibusb *,struct dib_fe_xfer_ops *);
241
242/* i2c and transfer stuff */
243#define DIBUSB_I2C_TIMEOUT 5000
244
245/*
246 * protocol of all dibusb related devices
247 */
248
249/*
250 * bulk msg to/from endpoint 0x01
251 *
252 * general structure:
253 * request_byte parameter_bytes
254 */
255
256#define DIBUSB_REQ_START_READ 0x00
257#define DIBUSB_REQ_START_DEMOD 0x01
258
259/*
260 * i2c read
261 * bulk write: 0x02 ((7bit i2c_addr << 1) & 0x01) register_bytes length_word
262 * bulk read: byte_buffer (length_word bytes)
263 */
264#define DIBUSB_REQ_I2C_READ 0x02
265
266/*
267 * i2c write
268 * bulk write: 0x03 (7bit i2c_addr << 1) register_bytes value_bytes
269 */
270#define DIBUSB_REQ_I2C_WRITE 0x03
271
272/*
273 * polling the value of the remote control
274 * bulk write: 0x04
275 * bulk read: byte_buffer (5 bytes)
276 *
277 * first byte of byte_buffer shows the status (0x00, 0x01, 0x02)
278 */
279#define DIBUSB_REQ_POLL_REMOTE 0x04
280
281#define DIBUSB_RC_NEC_EMPTY 0x00
282#define DIBUSB_RC_NEC_KEY_PRESSED 0x01
283#define DIBUSB_RC_NEC_KEY_REPEATED 0x02
284
285/* additional status values for Hauppauge Remote Control Protocol */
286#define DIBUSB_RC_HAUPPAUGE_KEY_PRESSED 0x01
287#define DIBUSB_RC_HAUPPAUGE_KEY_EMPTY 0x03
288
289/* streaming mode:
290 * bulk write: 0x05 mode_byte
291 *
292 * mode_byte is mostly 0x00
293 */
294#define DIBUSB_REQ_SET_STREAMING_MODE 0x05
295
296/* interrupt the internal read loop, when blocking */
297#define DIBUSB_REQ_INTR_READ 0x06
298
299/* io control
300 * 0x07 cmd_byte param_bytes
301 *
302 * param_bytes can be up to 32 bytes
303 *
304 * cmd_byte function parameter name
305 * 0x00 power mode
306 * 0x00 sleep
307 * 0x01 wakeup
308 *
309 * 0x01 enable streaming
310 * 0x02 disable streaming
311 *
312 *
313 */
314#define DIBUSB_REQ_SET_IOCTL 0x07
315
316/* IOCTL commands */
317
318/* change the power mode in firmware */
319#define DIBUSB_IOCTL_CMD_POWER_MODE 0x00
320#define DIBUSB_IOCTL_POWER_SLEEP 0x00
321#define DIBUSB_IOCTL_POWER_WAKEUP 0x01
322
323/* modify streaming of the FX2 */
324#define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01
325#define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02
326
327#endif
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 1863f1dfb00c..c225de7ffd82 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -175,8 +175,8 @@ static inline void dvb_dmxdev_dvr_state_set(struct dmxdev_dvr *dmxdevdvr, int st
175 175
176static int dvb_dvr_open(struct inode *inode, struct file *file) 176static int dvb_dvr_open(struct inode *inode, struct file *file)
177{ 177{
178 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; 178 struct dvb_device *dvbdev = file->private_data;
179 struct dmxdev *dmxdev=(struct dmxdev *) dvbdev->priv; 179 struct dmxdev *dmxdev = dvbdev->priv;
180 struct dmx_frontend *front; 180 struct dmx_frontend *front;
181 181
182 dprintk ("function : %s\n", __FUNCTION__); 182 dprintk ("function : %s\n", __FUNCTION__);
@@ -224,8 +224,8 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
224 224
225static int dvb_dvr_release(struct inode *inode, struct file *file) 225static int dvb_dvr_release(struct inode *inode, struct file *file)
226{ 226{
227 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; 227 struct dvb_device *dvbdev = file->private_data;
228 struct dmxdev *dmxdev=(struct dmxdev *) dvbdev->priv; 228 struct dmxdev *dmxdev = dvbdev->priv;
229 229
230 if (down_interruptible (&dmxdev->mutex)) 230 if (down_interruptible (&dmxdev->mutex))
231 return -ERESTARTSYS; 231 return -ERESTARTSYS;
@@ -252,8 +252,8 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
252static ssize_t dvb_dvr_write(struct file *file, const char __user *buf, 252static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
253 size_t count, loff_t *ppos) 253 size_t count, loff_t *ppos)
254{ 254{
255 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; 255 struct dvb_device *dvbdev = file->private_data;
256 struct dmxdev *dmxdev=(struct dmxdev *) dvbdev->priv; 256 struct dmxdev *dmxdev = dvbdev->priv;
257 int ret; 257 int ret;
258 258
259 if (!dmxdev->demux->write) 259 if (!dmxdev->demux->write)
@@ -270,8 +270,8 @@ static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
270static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count, 270static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
271 loff_t *ppos) 271 loff_t *ppos)
272{ 272{
273 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; 273 struct dvb_device *dvbdev = file->private_data;
274 struct dmxdev *dmxdev=(struct dmxdev *) dvbdev->priv; 274 struct dmxdev *dmxdev = dvbdev->priv;
275 int ret; 275 int ret;
276 276
277 //down(&dmxdev->mutex); 277 //down(&dmxdev->mutex);
@@ -345,7 +345,7 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
345 const u8 *buffer2, size_t buffer2_len, 345 const u8 *buffer2, size_t buffer2_len,
346 struct dmx_section_filter *filter, enum dmx_success success) 346 struct dmx_section_filter *filter, enum dmx_success success)
347{ 347{
348 struct dmxdev_filter *dmxdevfilter=(struct dmxdev_filter *) filter->priv; 348 struct dmxdev_filter *dmxdevfilter = filter->priv;
349 int ret; 349 int ret;
350 350
351 if (dmxdevfilter->buffer.error) { 351 if (dmxdevfilter->buffer.error) {
@@ -381,7 +381,7 @@ static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
381 const u8 *buffer2, size_t buffer2_len, 381 const u8 *buffer2, size_t buffer2_len,
382 struct dmx_ts_feed *feed, enum dmx_success success) 382 struct dmx_ts_feed *feed, enum dmx_success success)
383{ 383{
384 struct dmxdev_filter *dmxdevfilter=(struct dmxdev_filter *) feed->priv; 384 struct dmxdev_filter *dmxdevfilter = feed->priv;
385 struct dmxdev_buffer *buffer; 385 struct dmxdev_buffer *buffer;
386 int ret; 386 int ret;
387 387
@@ -684,8 +684,8 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
684 684
685static int dvb_demux_open(struct inode *inode, struct file *file) 685static int dvb_demux_open(struct inode *inode, struct file *file)
686{ 686{
687 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; 687 struct dvb_device *dvbdev = file->private_data;
688 struct dmxdev *dmxdev=(struct dmxdev *) dvbdev->priv; 688 struct dmxdev *dmxdev = dvbdev->priv;
689 int i; 689 int i;
690 struct dmxdev_filter *dmxdevfilter; 690 struct dmxdev_filter *dmxdevfilter;
691 691
@@ -1013,8 +1013,8 @@ static struct dvb_device dvbdev_demux = {
1013static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, 1013static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
1014 unsigned int cmd, void *parg) 1014 unsigned int cmd, void *parg)
1015{ 1015{
1016 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; 1016 struct dvb_device *dvbdev = file->private_data;
1017 struct dmxdev *dmxdev=(struct dmxdev *) dvbdev->priv; 1017 struct dmxdev *dmxdev = dvbdev->priv;
1018 1018
1019 int ret=0; 1019 int ret=0;
1020 1020
@@ -1044,8 +1044,8 @@ static int dvb_dvr_ioctl(struct inode *inode, struct file *file,
1044 1044
1045static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait) 1045static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait)
1046{ 1046{
1047 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1047 struct dvb_device *dvbdev = file->private_data;
1048 struct dmxdev *dmxdev = (struct dmxdev *) dvbdev->priv; 1048 struct dmxdev *dmxdev = dvbdev->priv;
1049 unsigned int mask = 0; 1049 unsigned int mask = 0;
1050 1050
1051 dprintk ("function : %s\n", __FUNCTION__); 1051 dprintk ("function : %s\n", __FUNCTION__);
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index c1ea89f2880c..0eb9aa711fb0 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -829,7 +829,7 @@ EXPORT_SYMBOL(dvb_ca_en50221_camready_irq);
829 */ 829 */
830void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221 *pubca, int slot, int change_type) 830void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221 *pubca, int slot, int change_type)
831{ 831{
832 struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; 832 struct dvb_ca_private *ca = pubca->private;
833 833
834 dprintk("CAMCHANGE IRQ slot:%i change_type:%i\n", slot, change_type); 834 dprintk("CAMCHANGE IRQ slot:%i change_type:%i\n", slot, change_type);
835 835
@@ -857,7 +857,7 @@ EXPORT_SYMBOL(dvb_ca_en50221_frda_irq);
857 */ 857 */
858void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221 *pubca, int slot) 858void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221 *pubca, int slot)
859{ 859{
860 struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; 860 struct dvb_ca_private *ca = pubca->private;
861 861
862 dprintk("CAMREADY IRQ slot:%i\n", slot); 862 dprintk("CAMREADY IRQ slot:%i\n", slot);
863 863
@@ -876,7 +876,7 @@ void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221 *pubca, int slot)
876 */ 876 */
877void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221 *pubca, int slot) 877void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221 *pubca, int slot)
878{ 878{
879 struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; 879 struct dvb_ca_private *ca = pubca->private;
880 int flags; 880 int flags;
881 881
882 dprintk("FR/DA IRQ slot:%i\n", slot); 882 dprintk("FR/DA IRQ slot:%i\n", slot);
@@ -993,7 +993,7 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca)
993 */ 993 */
994static int dvb_ca_en50221_thread(void *data) 994static int dvb_ca_en50221_thread(void *data)
995{ 995{
996 struct dvb_ca_private *ca = (struct dvb_ca_private *) data; 996 struct dvb_ca_private *ca = data;
997 char name[15]; 997 char name[15];
998 int slot; 998 int slot;
999 int flags; 999 int flags;
@@ -1202,8 +1202,8 @@ static int dvb_ca_en50221_thread(void *data)
1202static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file, 1202static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file,
1203 unsigned int cmd, void *parg) 1203 unsigned int cmd, void *parg)
1204{ 1204{
1205 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1205 struct dvb_device *dvbdev = file->private_data;
1206 struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; 1206 struct dvb_ca_private *ca = dvbdev->priv;
1207 int err = 0; 1207 int err = 0;
1208 int slot; 1208 int slot;
1209 1209
@@ -1225,7 +1225,7 @@ static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file,
1225 break; 1225 break;
1226 1226
1227 case CA_GET_CAP: { 1227 case CA_GET_CAP: {
1228 struct ca_caps *caps = (struct ca_caps *) parg; 1228 struct ca_caps *caps = parg;
1229 1229
1230 caps->slot_num = ca->slot_count; 1230 caps->slot_num = ca->slot_count;
1231 caps->slot_type = CA_CI_LINK; 1231 caps->slot_type = CA_CI_LINK;
@@ -1235,7 +1235,7 @@ static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file,
1235 } 1235 }
1236 1236
1237 case CA_GET_SLOT_INFO: { 1237 case CA_GET_SLOT_INFO: {
1238 struct ca_slot_info *info = (struct ca_slot_info *) parg; 1238 struct ca_slot_info *info = parg;
1239 1239
1240 if ((info->num > ca->slot_count) || (info->num < 0)) 1240 if ((info->num > ca->slot_count) || (info->num < 0))
1241 return -EINVAL; 1241 return -EINVAL;
@@ -1291,8 +1291,8 @@ static int dvb_ca_en50221_io_ioctl(struct inode *inode, struct file *file,
1291static ssize_t dvb_ca_en50221_io_write(struct file *file, 1291static ssize_t dvb_ca_en50221_io_write(struct file *file,
1292 const char __user * buf, size_t count, loff_t * ppos) 1292 const char __user * buf, size_t count, loff_t * ppos)
1293{ 1293{
1294 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1294 struct dvb_device *dvbdev = file->private_data;
1295 struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; 1295 struct dvb_ca_private *ca = dvbdev->priv;
1296 u8 slot, connection_id; 1296 u8 slot, connection_id;
1297 int status; 1297 int status;
1298 char fragbuf[HOST_LINK_BUF_SIZE]; 1298 char fragbuf[HOST_LINK_BUF_SIZE];
@@ -1428,8 +1428,8 @@ static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private *ca, int *resu
1428static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user * buf, 1428static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user * buf,
1429 size_t count, loff_t * ppos) 1429 size_t count, loff_t * ppos)
1430{ 1430{
1431 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1431 struct dvb_device *dvbdev = file->private_data;
1432 struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; 1432 struct dvb_ca_private *ca = dvbdev->priv;
1433 int status; 1433 int status;
1434 int result = 0; 1434 int result = 0;
1435 u8 hdr[2]; 1435 u8 hdr[2];
@@ -1526,8 +1526,8 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user * buf,
1526 */ 1526 */
1527static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file) 1527static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file)
1528{ 1528{
1529 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1529 struct dvb_device *dvbdev = file->private_data;
1530 struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; 1530 struct dvb_ca_private *ca = dvbdev->priv;
1531 int err; 1531 int err;
1532 int i; 1532 int i;
1533 1533
@@ -1569,8 +1569,8 @@ static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file)
1569 */ 1569 */
1570static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file) 1570static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file)
1571{ 1571{
1572 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1572 struct dvb_device *dvbdev = file->private_data;
1573 struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; 1573 struct dvb_ca_private *ca = dvbdev->priv;
1574 int err = 0; 1574 int err = 0;
1575 1575
1576 dprintk("%s\n", __FUNCTION__); 1576 dprintk("%s\n", __FUNCTION__);
@@ -1597,8 +1597,8 @@ static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file)
1597 */ 1597 */
1598static unsigned int dvb_ca_en50221_io_poll(struct file *file, poll_table * wait) 1598static unsigned int dvb_ca_en50221_io_poll(struct file *file, poll_table * wait)
1599{ 1599{
1600 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1600 struct dvb_device *dvbdev = file->private_data;
1601 struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; 1601 struct dvb_ca_private *ca = dvbdev->priv;
1602 unsigned int mask = 0; 1602 unsigned int mask = 0;
1603 int slot; 1603 int slot;
1604 int result = 0; 1604 int result = 0;
@@ -1750,7 +1750,7 @@ EXPORT_SYMBOL(dvb_ca_en50221_release);
1750 */ 1750 */
1751void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca) 1751void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca)
1752{ 1752{
1753 struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; 1753 struct dvb_ca_private *ca = pubca->private;
1754 int i; 1754 int i;
1755 1755
1756 dprintk("%s\n", __FUNCTION__); 1756 dprintk("%s\n", __FUNCTION__);
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 59a9adfae1eb..f11daae91cd4 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -35,6 +35,7 @@
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/list.h> 36#include <linux/list.h>
37#include <linux/suspend.h> 37#include <linux/suspend.h>
38#include <linux/jiffies.h>
38#include <asm/processor.h> 39#include <asm/processor.h>
39#include <asm/semaphore.h> 40#include <asm/semaphore.h>
40 41
@@ -48,7 +49,7 @@ static int dvb_override_tune_delay;
48static int dvb_powerdown_on_sleep = 1; 49static int dvb_powerdown_on_sleep = 1;
49 50
50module_param_named(frontend_debug, dvb_frontend_debug, int, 0644); 51module_param_named(frontend_debug, dvb_frontend_debug, int, 0644);
51MODULE_PARM_DESC(dvb_frontend_debug, "Turn on/off frontend core debugging (default:off)."); 52MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off).");
52module_param(dvb_shutdown_timeout, int, 0444); 53module_param(dvb_shutdown_timeout, int, 0444);
53MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware"); 54MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware");
54module_param(dvb_force_auto_inversion, int, 0444); 55module_param(dvb_force_auto_inversion, int, 0444);
@@ -117,7 +118,7 @@ struct dvb_frontend_private {
117 118
118static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status) 119static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
119{ 120{
120 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 121 struct dvb_frontend_private *fepriv = fe->frontend_priv;
121 struct dvb_fe_events *events = &fepriv->events; 122 struct dvb_fe_events *events = &fepriv->events;
122 struct dvb_frontend_event *e; 123 struct dvb_frontend_event *e;
123 int wp; 124 int wp;
@@ -155,7 +156,7 @@ static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
155static int dvb_frontend_get_event(struct dvb_frontend *fe, 156static int dvb_frontend_get_event(struct dvb_frontend *fe,
156 struct dvb_frontend_event *event, int flags) 157 struct dvb_frontend_event *event, int flags)
157{ 158{
158 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 159 struct dvb_frontend_private *fepriv = fe->frontend_priv;
159 struct dvb_fe_events *events = &fepriv->events; 160 struct dvb_fe_events *events = &fepriv->events;
160 161
161 dprintk ("%s\n", __FUNCTION__); 162 dprintk ("%s\n", __FUNCTION__);
@@ -234,7 +235,7 @@ static int dvb_frontend_autotune(struct dvb_frontend *fe, int check_wrapped)
234{ 235{
235 int autoinversion; 236 int autoinversion;
236 int ready = 0; 237 int ready = 0;
237 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 238 struct dvb_frontend_private *fepriv = fe->frontend_priv;
238 int original_inversion = fepriv->parameters.inversion; 239 int original_inversion = fepriv->parameters.inversion;
239 u32 original_frequency = fepriv->parameters.frequency; 240 u32 original_frequency = fepriv->parameters.frequency;
240 241
@@ -321,13 +322,14 @@ static int dvb_frontend_autotune(struct dvb_frontend *fe, int check_wrapped)
321 322
322static int dvb_frontend_is_exiting(struct dvb_frontend *fe) 323static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
323{ 324{
324 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 325 struct dvb_frontend_private *fepriv = fe->frontend_priv;
325 326
326 if (fepriv->exit) 327 if (fepriv->exit)
327 return 1; 328 return 1;
328 329
329 if (fepriv->dvbdev->writers == 1) 330 if (fepriv->dvbdev->writers == 1)
330 if (jiffies - fepriv->release_jiffies > dvb_shutdown_timeout * HZ) 331 if (time_after(jiffies, fepriv->release_jiffies +
332 dvb_shutdown_timeout * HZ))
331 return 1; 333 return 1;
332 334
333 return 0; 335 return 0;
@@ -335,7 +337,7 @@ static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
335 337
336static int dvb_frontend_should_wakeup(struct dvb_frontend *fe) 338static int dvb_frontend_should_wakeup(struct dvb_frontend *fe)
337{ 339{
338 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 340 struct dvb_frontend_private *fepriv = fe->frontend_priv;
339 341
340 if (fepriv->wakeup) { 342 if (fepriv->wakeup) {
341 fepriv->wakeup = 0; 343 fepriv->wakeup = 0;
@@ -346,7 +348,7 @@ static int dvb_frontend_should_wakeup(struct dvb_frontend *fe)
346 348
347static void dvb_frontend_wakeup(struct dvb_frontend *fe) 349static void dvb_frontend_wakeup(struct dvb_frontend *fe)
348{ 350{
349 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 351 struct dvb_frontend_private *fepriv = fe->frontend_priv;
350 352
351 fepriv->wakeup = 1; 353 fepriv->wakeup = 1;
352 wake_up_interruptible(&fepriv->wait_queue); 354 wake_up_interruptible(&fepriv->wait_queue);
@@ -357,8 +359,8 @@ static void dvb_frontend_wakeup(struct dvb_frontend *fe)
357 */ 359 */
358static int dvb_frontend_thread(void *data) 360static int dvb_frontend_thread(void *data)
359{ 361{
360 struct dvb_frontend *fe = (struct dvb_frontend *) data; 362 struct dvb_frontend *fe = data;
361 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 363 struct dvb_frontend_private *fepriv = fe->frontend_priv;
362 unsigned long timeout; 364 unsigned long timeout;
363 char name [15]; 365 char name [15];
364 int quality = 0, delay = 3*HZ; 366 int quality = 0, delay = 3*HZ;
@@ -389,8 +391,7 @@ static int dvb_frontend_thread(void *data)
389 break; 391 break;
390 } 392 }
391 393
392 if (current->flags & PF_FREEZE) 394 try_to_freeze();
393 refrigerator(PF_FREEZE);
394 395
395 if (down_interruptible(&fepriv->sem)) 396 if (down_interruptible(&fepriv->sem))
396 break; 397 break;
@@ -520,7 +521,7 @@ static int dvb_frontend_thread(void *data)
520static void dvb_frontend_stop(struct dvb_frontend *fe) 521static void dvb_frontend_stop(struct dvb_frontend *fe)
521{ 522{
522 unsigned long ret; 523 unsigned long ret;
523 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 524 struct dvb_frontend_private *fepriv = fe->frontend_priv;
524 525
525 dprintk ("%s\n", __FUNCTION__); 526 dprintk ("%s\n", __FUNCTION__);
526 527
@@ -559,7 +560,7 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
559static int dvb_frontend_start(struct dvb_frontend *fe) 560static int dvb_frontend_start(struct dvb_frontend *fe)
560{ 561{
561 int ret; 562 int ret;
562 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 563 struct dvb_frontend_private *fepriv = fe->frontend_priv;
563 564
564 dprintk ("%s\n", __FUNCTION__); 565 dprintk ("%s\n", __FUNCTION__);
565 566
@@ -597,7 +598,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
597{ 598{
598 struct dvb_device *dvbdev = file->private_data; 599 struct dvb_device *dvbdev = file->private_data;
599 struct dvb_frontend *fe = dvbdev->priv; 600 struct dvb_frontend *fe = dvbdev->priv;
600 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 601 struct dvb_frontend_private *fepriv = fe->frontend_priv;
601 int err = -EOPNOTSUPP; 602 int err = -EOPNOTSUPP;
602 603
603 dprintk ("%s\n", __FUNCTION__); 604 dprintk ("%s\n", __FUNCTION__);
@@ -615,7 +616,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
615 616
616 switch (cmd) { 617 switch (cmd) {
617 case FE_GET_INFO: { 618 case FE_GET_INFO: {
618 struct dvb_frontend_info* info = (struct dvb_frontend_info*) parg; 619 struct dvb_frontend_info* info = parg;
619 memcpy(info, &fe->ops->info, sizeof(struct dvb_frontend_info)); 620 memcpy(info, &fe->ops->info, sizeof(struct dvb_frontend_info));
620 621
621 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't 622 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't
@@ -793,7 +794,7 @@ static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struc
793{ 794{
794 struct dvb_device *dvbdev = file->private_data; 795 struct dvb_device *dvbdev = file->private_data;
795 struct dvb_frontend *fe = dvbdev->priv; 796 struct dvb_frontend *fe = dvbdev->priv;
796 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 797 struct dvb_frontend_private *fepriv = fe->frontend_priv;
797 798
798 dprintk ("%s\n", __FUNCTION__); 799 dprintk ("%s\n", __FUNCTION__);
799 800
@@ -809,7 +810,7 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
809{ 810{
810 struct dvb_device *dvbdev = file->private_data; 811 struct dvb_device *dvbdev = file->private_data;
811 struct dvb_frontend *fe = dvbdev->priv; 812 struct dvb_frontend *fe = dvbdev->priv;
812 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 813 struct dvb_frontend_private *fepriv = fe->frontend_priv;
813 int ret; 814 int ret;
814 815
815 dprintk ("%s\n", __FUNCTION__); 816 dprintk ("%s\n", __FUNCTION__);
@@ -833,7 +834,7 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
833{ 834{
834 struct dvb_device *dvbdev = file->private_data; 835 struct dvb_device *dvbdev = file->private_data;
835 struct dvb_frontend *fe = dvbdev->priv; 836 struct dvb_frontend *fe = dvbdev->priv;
836 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 837 struct dvb_frontend_private *fepriv = fe->frontend_priv;
837 838
838 dprintk ("%s\n", __FUNCTION__); 839 dprintk ("%s\n", __FUNCTION__);
839 840
@@ -873,7 +874,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
873 up(&frontend_mutex); 874 up(&frontend_mutex);
874 return -ENOMEM; 875 return -ENOMEM;
875 } 876 }
876 fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 877 fepriv = fe->frontend_priv;
877 memset(fe->frontend_priv, 0, sizeof(struct dvb_frontend_private)); 878 memset(fe->frontend_priv, 0, sizeof(struct dvb_frontend_private));
878 879
879 init_MUTEX (&fepriv->sem); 880 init_MUTEX (&fepriv->sem);
@@ -897,7 +898,7 @@ EXPORT_SYMBOL(dvb_register_frontend);
897 898
898int dvb_unregister_frontend(struct dvb_frontend* fe) 899int dvb_unregister_frontend(struct dvb_frontend* fe)
899{ 900{
900 struct dvb_frontend_private *fepriv = (struct dvb_frontend_private*) fe->frontend_priv; 901 struct dvb_frontend_private *fepriv = fe->frontend_priv;
901 dprintk ("%s\n", __FUNCTION__); 902 dprintk ("%s\n", __FUNCTION__);
902 903
903 down (&frontend_mutex); 904 down (&frontend_mutex);
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 44892e7abd3d..6a968c346a36 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -315,7 +315,7 @@ static inline void reset_ule( struct dvb_net_priv *p )
315 */ 315 */
316static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len ) 316static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
317{ 317{
318 struct dvb_net_priv *priv = (struct dvb_net_priv *)dev->priv; 318 struct dvb_net_priv *priv = dev->priv;
319 unsigned long skipped = 0L; 319 unsigned long skipped = 0L;
320 u8 *ts, *ts_end, *from_where = NULL, ts_remain = 0, how_much = 0, new_ts = 1; 320 u8 *ts, *ts_end, *from_where = NULL, ts_remain = 0, how_much = 0, new_ts = 1;
321 struct ethhdr *ethh = NULL; 321 struct ethhdr *ethh = NULL;
@@ -709,7 +709,7 @@ static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len,
709 const u8 *buffer2, size_t buffer2_len, 709 const u8 *buffer2, size_t buffer2_len,
710 struct dmx_ts_feed *feed, enum dmx_success success) 710 struct dmx_ts_feed *feed, enum dmx_success success)
711{ 711{
712 struct net_device *dev = (struct net_device *)feed->priv; 712 struct net_device *dev = feed->priv;
713 713
714 if (buffer2 != 0) 714 if (buffer2 != 0)
715 printk(KERN_WARNING "buffer2 not 0: %p.\n", buffer2); 715 printk(KERN_WARNING "buffer2 not 0: %p.\n", buffer2);
@@ -727,6 +727,7 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
727 u8 *eth; 727 u8 *eth;
728 struct sk_buff *skb; 728 struct sk_buff *skb;
729 struct net_device_stats *stats = &(((struct dvb_net_priv *) dev->priv)->stats); 729 struct net_device_stats *stats = &(((struct dvb_net_priv *) dev->priv)->stats);
730 int snap = 0;
730 731
731 /* note: pkt_len includes a 32bit checksum */ 732 /* note: pkt_len includes a 32bit checksum */
732 if (pkt_len < 16) { 733 if (pkt_len < 16) {
@@ -750,9 +751,12 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
750 return; 751 return;
751 } 752 }
752 if (pkt[5] & 0x02) { 753 if (pkt[5] & 0x02) {
753 //FIXME: handle LLC/SNAP 754 /* handle LLC/SNAP, see rfc-1042 */
754 stats->rx_dropped++; 755 if (pkt_len < 24 || memcmp(&pkt[12], "\xaa\xaa\x03\0\0\0", 6)) {
755 return; 756 stats->rx_dropped++;
757 return;
758 }
759 snap = 8;
756 } 760 }
757 if (pkt[7]) { 761 if (pkt[7]) {
758 /* FIXME: assemble datagram from multiple sections */ 762 /* FIXME: assemble datagram from multiple sections */
@@ -762,9 +766,9 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
762 } 766 }
763 767
764 /* we have 14 byte ethernet header (ip header follows); 768 /* we have 14 byte ethernet header (ip header follows);
765 * 12 byte MPE header; 4 byte checksum; + 2 byte alignment 769 * 12 byte MPE header; 4 byte checksum; + 2 byte alignment, 8 byte LLC/SNAP
766 */ 770 */
767 if (!(skb = dev_alloc_skb(pkt_len - 4 - 12 + 14 + 2))) { 771 if (!(skb = dev_alloc_skb(pkt_len - 4 - 12 + 14 + 2 - snap))) {
768 //printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name); 772 //printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
769 stats->rx_dropped++; 773 stats->rx_dropped++;
770 return; 774 return;
@@ -773,8 +777,8 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
773 skb->dev = dev; 777 skb->dev = dev;
774 778
775 /* copy L3 payload */ 779 /* copy L3 payload */
776 eth = (u8 *) skb_put(skb, pkt_len - 12 - 4 + 14); 780 eth = (u8 *) skb_put(skb, pkt_len - 12 - 4 + 14 - snap);
777 memcpy(eth + 14, pkt + 12, pkt_len - 12 - 4); 781 memcpy(eth + 14, pkt + 12 + snap, pkt_len - 12 - 4 - snap);
778 782
779 /* create ethernet header: */ 783 /* create ethernet header: */
780 eth[0]=pkt[0x0b]; 784 eth[0]=pkt[0x0b];
@@ -786,8 +790,21 @@ static void dvb_net_sec(struct net_device *dev, u8 *pkt, int pkt_len)
786 790
787 eth[6]=eth[7]=eth[8]=eth[9]=eth[10]=eth[11]=0; 791 eth[6]=eth[7]=eth[8]=eth[9]=eth[10]=eth[11]=0;
788 792
789 eth[12] = 0x08; /* ETH_P_IP */ 793 if (snap) {
790 eth[13] = 0x00; 794 eth[12] = pkt[18];
795 eth[13] = pkt[19];
796 } else {
797 /* protocol numbers are from rfc-1700 or
798 * http://www.iana.org/assignments/ethernet-numbers
799 */
800 if (pkt[12] >> 4 == 6) { /* version field from IP header */
801 eth[12] = 0x86; /* IPv6 */
802 eth[13] = 0xdd;
803 } else {
804 eth[12] = 0x08; /* IPv4 */
805 eth[13] = 0x00;
806 }
807 }
791 808
792 skb->protocol = dvb_net_eth_type_trans(skb, dev); 809 skb->protocol = dvb_net_eth_type_trans(skb, dev);
793 810
@@ -801,7 +818,7 @@ static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len,
801 struct dmx_section_filter *filter, 818 struct dmx_section_filter *filter,
802 enum dmx_success success) 819 enum dmx_success success)
803{ 820{
804 struct net_device *dev=(struct net_device *) filter->priv; 821 struct net_device *dev = filter->priv;
805 822
806 /** 823 /**
807 * we rely on the DVB API definition where exactly one complete 824 * we rely on the DVB API definition where exactly one complete
@@ -826,7 +843,7 @@ static int dvb_net_filter_sec_set(struct net_device *dev,
826 struct dmx_section_filter **secfilter, 843 struct dmx_section_filter **secfilter,
827 u8 *mac, u8 *mac_mask) 844 u8 *mac, u8 *mac_mask)
828{ 845{
829 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 846 struct dvb_net_priv *priv = dev->priv;
830 int ret; 847 int ret;
831 848
832 *secfilter=NULL; 849 *secfilter=NULL;
@@ -870,7 +887,7 @@ static int dvb_net_filter_sec_set(struct net_device *dev,
870static int dvb_net_feed_start(struct net_device *dev) 887static int dvb_net_feed_start(struct net_device *dev)
871{ 888{
872 int ret, i; 889 int ret, i;
873 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 890 struct dvb_net_priv *priv = dev->priv;
874 struct dmx_demux *demux = priv->demux; 891 struct dmx_demux *demux = priv->demux;
875 unsigned char *mac = (unsigned char *) dev->dev_addr; 892 unsigned char *mac = (unsigned char *) dev->dev_addr;
876 893
@@ -965,7 +982,7 @@ static int dvb_net_feed_start(struct net_device *dev)
965 982
966static int dvb_net_feed_stop(struct net_device *dev) 983static int dvb_net_feed_stop(struct net_device *dev)
967{ 984{
968 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 985 struct dvb_net_priv *priv = dev->priv;
969 int i; 986 int i;
970 987
971 dprintk("%s\n", __FUNCTION__); 988 dprintk("%s\n", __FUNCTION__);
@@ -1016,7 +1033,7 @@ static int dvb_net_feed_stop(struct net_device *dev)
1016 1033
1017static int dvb_set_mc_filter (struct net_device *dev, struct dev_mc_list *mc) 1034static int dvb_set_mc_filter (struct net_device *dev, struct dev_mc_list *mc)
1018{ 1035{
1019 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 1036 struct dvb_net_priv *priv = dev->priv;
1020 1037
1021 if (priv->multi_num == DVB_NET_MULTICAST_MAX) 1038 if (priv->multi_num == DVB_NET_MULTICAST_MAX)
1022 return -ENOMEM; 1039 return -ENOMEM;
@@ -1031,7 +1048,7 @@ static int dvb_set_mc_filter (struct net_device *dev, struct dev_mc_list *mc)
1031static void wq_set_multicast_list (void *data) 1048static void wq_set_multicast_list (void *data)
1032{ 1049{
1033 struct net_device *dev = data; 1050 struct net_device *dev = data;
1034 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 1051 struct dvb_net_priv *priv = dev->priv;
1035 1052
1036 dvb_net_feed_stop(dev); 1053 dvb_net_feed_stop(dev);
1037 1054
@@ -1066,7 +1083,7 @@ static void wq_set_multicast_list (void *data)
1066 1083
1067static void dvb_net_set_multicast_list (struct net_device *dev) 1084static void dvb_net_set_multicast_list (struct net_device *dev)
1068{ 1085{
1069 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 1086 struct dvb_net_priv *priv = dev->priv;
1070 schedule_work(&priv->set_multicast_list_wq); 1087 schedule_work(&priv->set_multicast_list_wq);
1071} 1088}
1072 1089
@@ -1084,7 +1101,7 @@ static void wq_restart_net_feed (void *data)
1084 1101
1085static int dvb_net_set_mac (struct net_device *dev, void *p) 1102static int dvb_net_set_mac (struct net_device *dev, void *p)
1086{ 1103{
1087 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 1104 struct dvb_net_priv *priv = dev->priv;
1088 struct sockaddr *addr=p; 1105 struct sockaddr *addr=p;
1089 1106
1090 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); 1107 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
@@ -1098,7 +1115,7 @@ static int dvb_net_set_mac (struct net_device *dev, void *p)
1098 1115
1099static int dvb_net_open(struct net_device *dev) 1116static int dvb_net_open(struct net_device *dev)
1100{ 1117{
1101 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 1118 struct dvb_net_priv *priv = dev->priv;
1102 1119
1103 priv->in_use++; 1120 priv->in_use++;
1104 dvb_net_feed_start(dev); 1121 dvb_net_feed_start(dev);
@@ -1108,7 +1125,7 @@ static int dvb_net_open(struct net_device *dev)
1108 1125
1109static int dvb_net_stop(struct net_device *dev) 1126static int dvb_net_stop(struct net_device *dev)
1110{ 1127{
1111 struct dvb_net_priv *priv = (struct dvb_net_priv*) dev->priv; 1128 struct dvb_net_priv *priv = dev->priv;
1112 1129
1113 priv->in_use--; 1130 priv->in_use--;
1114 return dvb_net_feed_stop(dev); 1131 return dvb_net_feed_stop(dev);
@@ -1228,8 +1245,8 @@ static int dvb_net_remove_if(struct dvb_net *dvbnet, unsigned int num)
1228static int dvb_net_do_ioctl(struct inode *inode, struct file *file, 1245static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
1229 unsigned int cmd, void *parg) 1246 unsigned int cmd, void *parg)
1230{ 1247{
1231 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; 1248 struct dvb_device *dvbdev = file->private_data;
1232 struct dvb_net *dvbnet = (struct dvb_net *) dvbdev->priv; 1249 struct dvb_net *dvbnet = dvbdev->priv;
1233 1250
1234 if (((file->f_flags&O_ACCMODE)==O_RDONLY)) 1251 if (((file->f_flags&O_ACCMODE)==O_RDONLY))
1235 return -EPERM; 1252 return -EPERM;
@@ -1237,7 +1254,7 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
1237 switch (cmd) { 1254 switch (cmd) {
1238 case NET_ADD_IF: 1255 case NET_ADD_IF:
1239 { 1256 {
1240 struct dvb_net_if *dvbnetif=(struct dvb_net_if *)parg; 1257 struct dvb_net_if *dvbnetif = parg;
1241 int result; 1258 int result;
1242 1259
1243 if (!capable(CAP_SYS_ADMIN)) 1260 if (!capable(CAP_SYS_ADMIN))
@@ -1258,7 +1275,7 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
1258 { 1275 {
1259 struct net_device *netdev; 1276 struct net_device *netdev;
1260 struct dvb_net_priv *priv_data; 1277 struct dvb_net_priv *priv_data;
1261 struct dvb_net_if *dvbnetif=(struct dvb_net_if *)parg; 1278 struct dvb_net_if *dvbnetif = parg;
1262 1279
1263 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || 1280 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX ||
1264 !dvbnet->state[dvbnetif->if_num]) 1281 !dvbnet->state[dvbnetif->if_num])
@@ -1266,7 +1283,7 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
1266 1283
1267 netdev = dvbnet->device[dvbnetif->if_num]; 1284 netdev = dvbnet->device[dvbnetif->if_num];
1268 1285
1269 priv_data=(struct dvb_net_priv*)netdev->priv; 1286 priv_data = netdev->priv;
1270 dvbnetif->pid=priv_data->pid; 1287 dvbnetif->pid=priv_data->pid;
1271 dvbnetif->feedtype=priv_data->feedtype; 1288 dvbnetif->feedtype=priv_data->feedtype;
1272 break; 1289 break;
@@ -1288,7 +1305,7 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
1288 /* binary compatiblity cruft */ 1305 /* binary compatiblity cruft */
1289 case __NET_ADD_IF_OLD: 1306 case __NET_ADD_IF_OLD:
1290 { 1307 {
1291 struct __dvb_net_if_old *dvbnetif=(struct __dvb_net_if_old *)parg; 1308 struct __dvb_net_if_old *dvbnetif = parg;
1292 int result; 1309 int result;
1293 1310
1294 if (!capable(CAP_SYS_ADMIN)) 1311 if (!capable(CAP_SYS_ADMIN))
@@ -1309,7 +1326,7 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
1309 { 1326 {
1310 struct net_device *netdev; 1327 struct net_device *netdev;
1311 struct dvb_net_priv *priv_data; 1328 struct dvb_net_priv *priv_data;
1312 struct __dvb_net_if_old *dvbnetif=(struct __dvb_net_if_old *)parg; 1329 struct __dvb_net_if_old *dvbnetif = parg;
1313 1330
1314 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || 1331 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX ||
1315 !dvbnet->state[dvbnetif->if_num]) 1332 !dvbnet->state[dvbnetif->if_num])
@@ -1317,7 +1334,7 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
1317 1334
1318 netdev = dvbnet->device[dvbnetif->if_num]; 1335 netdev = dvbnet->device[dvbnetif->if_num];
1319 1336
1320 priv_data=(struct dvb_net_priv*)netdev->priv; 1337 priv_data = netdev->priv;
1321 dvbnetif->pid=priv_data->pid; 1338 dvbnetif->pid=priv_data->pid;
1322 break; 1339 break;
1323 } 1340 }
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index cf4ffe38fda3..4b7adca3e286 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -56,8 +56,7 @@ static const char * const dnames[] = {
56#define nums2minor(num,type,id) ((num << 6) | (id << 4) | type) 56#define nums2minor(num,type,id) ((num << 6) | (id << 4) | type)
57#define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64) 57#define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64)
58 58
59struct class_simple *dvb_class; 59static struct class *dvb_class;
60EXPORT_SYMBOL(dvb_class);
61 60
62static struct dvb_device* dvbdev_find_device (int minor) 61static struct dvb_device* dvbdev_find_device (int minor)
63{ 62{
@@ -236,8 +235,8 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
236 S_IFCHR | S_IRUSR | S_IWUSR, 235 S_IFCHR | S_IRUSR | S_IWUSR,
237 "dvb/adapter%d/%s%d", adap->num, dnames[type], id); 236 "dvb/adapter%d/%s%d", adap->num, dnames[type], id);
238 237
239 class_simple_device_add(dvb_class, MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)), 238 class_device_create(dvb_class, MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
240 NULL, "dvb%d.%s%d", adap->num, dnames[type], id); 239 NULL, "dvb%d.%s%d", adap->num, dnames[type], id);
241 240
242 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n", 241 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
243 adap->num, dnames[type], id, nums2minor(adap->num, type, id), 242 adap->num, dnames[type], id, nums2minor(adap->num, type, id),
@@ -256,7 +255,7 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
256 devfs_remove("dvb/adapter%d/%s%d", dvbdev->adapter->num, 255 devfs_remove("dvb/adapter%d/%s%d", dvbdev->adapter->num,
257 dnames[dvbdev->type], dvbdev->id); 256 dnames[dvbdev->type], dvbdev->id);
258 257
259 class_simple_device_remove(MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num, 258 class_device_destroy(dvb_class, MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num,
260 dvbdev->type, dvbdev->id))); 259 dvbdev->type, dvbdev->id)));
261 260
262 list_del (&dvbdev->list_head); 261 list_del (&dvbdev->list_head);
@@ -286,9 +285,8 @@ skip:
286} 285}
287 286
288 287
289int dvb_register_adapter(struct dvb_adapter **padap, const char *name, struct module *module) 288int dvb_register_adapter(struct dvb_adapter *adap, const char *name, struct module *module)
290{ 289{
291 struct dvb_adapter *adap;
292 int num; 290 int num;
293 291
294 if (down_interruptible (&dvbdev_register_lock)) 292 if (down_interruptible (&dvbdev_register_lock))
@@ -299,11 +297,6 @@ int dvb_register_adapter(struct dvb_adapter **padap, const char *name, struct mo
299 return -ENFILE; 297 return -ENFILE;
300 } 298 }
301 299
302 if (!(*padap = adap = kmalloc(sizeof(struct dvb_adapter), GFP_KERNEL))) {
303 up(&dvbdev_register_lock);
304 return -ENOMEM;
305 }
306
307 memset (adap, 0, sizeof(struct dvb_adapter)); 300 memset (adap, 0, sizeof(struct dvb_adapter));
308 INIT_LIST_HEAD (&adap->device_list); 301 INIT_LIST_HEAD (&adap->device_list);
309 302
@@ -331,7 +324,6 @@ int dvb_unregister_adapter(struct dvb_adapter *adap)
331 return -ERESTARTSYS; 324 return -ERESTARTSYS;
332 list_del (&adap->list_head); 325 list_del (&adap->list_head);
333 up (&dvbdev_register_lock); 326 up (&dvbdev_register_lock);
334 kfree (adap);
335 return 0; 327 return 0;
336} 328}
337EXPORT_SYMBOL(dvb_unregister_adapter); 329EXPORT_SYMBOL(dvb_unregister_adapter);
@@ -419,7 +411,7 @@ static int __init init_dvbdev(void)
419 411
420 devfs_mk_dir("dvb"); 412 devfs_mk_dir("dvb");
421 413
422 dvb_class = class_simple_create(THIS_MODULE, "dvb"); 414 dvb_class = class_create(THIS_MODULE, "dvb");
423 if (IS_ERR(dvb_class)) { 415 if (IS_ERR(dvb_class)) {
424 retval = PTR_ERR(dvb_class); 416 retval = PTR_ERR(dvb_class);
425 goto error; 417 goto error;
@@ -436,7 +428,7 @@ error:
436static void __exit exit_dvbdev(void) 428static void __exit exit_dvbdev(void)
437{ 429{
438 devfs_remove("dvb"); 430 devfs_remove("dvb");
439 class_simple_destroy(dvb_class); 431 class_destroy(dvb_class);
440 cdev_del(&dvb_device_cdev); 432 cdev_del(&dvb_device_cdev);
441 unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS); 433 unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS);
442} 434}
diff --git a/drivers/media/dvb/dvb-core/dvbdev.h b/drivers/media/dvb/dvb-core/dvbdev.h
index 184edba3caa7..a251867f30f1 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.h
+++ b/drivers/media/dvb/dvb-core/dvbdev.h
@@ -76,7 +76,7 @@ struct dvb_device {
76}; 76};
77 77
78 78
79extern int dvb_register_adapter (struct dvb_adapter **padap, const char *name, struct module *module); 79extern int dvb_register_adapter (struct dvb_adapter *adap, const char *name, struct module *module);
80extern int dvb_unregister_adapter (struct dvb_adapter *adap); 80extern int dvb_unregister_adapter (struct dvb_adapter *adap);
81 81
82extern int dvb_register_device (struct dvb_adapter *adap, 82extern int dvb_register_device (struct dvb_adapter *adap,
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
new file mode 100644
index 000000000000..8aa32f6e447b
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -0,0 +1,99 @@
1config DVB_USB
2 tristate "Support for various USB DVB devices"
3 depends on DVB_CORE && USB
4 select FW_LOADER
5 help
6 By enabling this you will be able to choose the various USB 1.1 and
7 USB2.0 DVB devices.
8
9 Almost every USB device needs a firmware, please look into
10 <file:Documentation/dvb/README.dvb-usb>
11
12 Say Y if you own an USB DVB device.
13
14config DVB_USB_DEBUG
15 bool "Enable extended debug support for all DVB-USB devices"
16 depends on DVB_USB
17 help
18 Say Y if you want to enable debuging. See modinfo dvb-usb (and the
19 appropriate drivers) for debug levels.
20
21config DVB_USB_A800
22 tristate "AVerMedia AverTV DVB-T USB 2.0 (A800)"
23 depends on DVB_USB
24 help
25 Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver.
26
27config DVB_USB_DIBUSB_MB
28 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-B) (see help for device list)"
29 depends on DVB_USB
30 help
31 Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by
32 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator.
33
34 Devices supported by this driver:
35 TwinhanDTV USB-Ter (VP7041)
36 TwinhanDTV Magic Box (VP7041e)
37 KWorld/JetWay/ADSTech V-Stream XPERT DTV - DVB-T USB1.1 and USB2.0
38 Hama DVB-T USB1.1-Box
39 DiBcom USB1.1 reference devices (non-public)
40 Ultima Electronic/Artec T1 USB TVBOX
41 Compro Videomate DVB-U2000 - DVB-T USB
42 Grandtec DVB-T USB
43 Avermedia AverTV DVBT USB1.1
44 Artec T1 USB1.1 boxes
45
46 The VP7041 seems to be identical to "CTS Portable" (Chinese
47 Television System).
48
49 Say Y if you own such a device and want to use it. You should build it as
50 a module.
51
52config DVB_USB_DIBUSB_MC
53 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)"
54 depends on DVB_USB
55 help
56 Support for 2.0 DVB-T receivers based on reference designs made by
57 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator.
58
59 Devices supported by this driver:
60 DiBcom USB2.0 reference devices (non-public)
61 Artec T1 USB2.0 boxes
62
63 Say Y if you own such a device and want to use it. You should build it as
64 a module.
65
66config DVB_USB_UMT_010
67 tristate "HanfTek UMT-010 DVB-T USB2.0 support"
68 depends on DVB_USB
69 help
70 Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver.
71
72config DVB_USB_DIGITV
73 tristate "Nebula Electronics uDigiTV DVB-T USB2.0 support"
74 depends on DVB_USB
75 help
76 Say Y here to support the Nebula Electronics uDigitV USB2.0 DVB-T receiver.
77
78config DVB_USB_VP7045
79 tristate "TwinhanDTV Alpha/MagicBoxII and DNTV tinyUSB2 DVB-T USB2.0 support"
80 depends on DVB_USB
81 help
82 Say Y here to support the
83 TwinhanDTV Alpha (stick) (VP-7045),
84 TwinhanDTV MagicBox II (VP-7046) and
85 DigitalNow TinyUSB 2 DVB-t DVB-T USB2.0 receivers.
86
87config DVB_USB_NOVA_T_USB2
88 tristate "Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 support"
89 depends on DVB_USB
90 help
91 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver.
92
93config DVB_USB_DTT200U
94 tristate "Yakumo/Hama/Typhoon/Yuan DVB-T USB2.0 support"
95 depends on DVB_USB
96 help
97 Say Y here to support the Yakumo/Hama/Typhoon/Yuan DVB-T USB2.0 receiver.
98
99 The receivers are also known as DTT200U (Yakumo) and UB300 (Yuan).
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
new file mode 100644
index 000000000000..d65b50f9abb0
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -0,0 +1,30 @@
1dvb-usb-objs = dvb-usb-firmware.o dvb-usb-init.o dvb-usb-urb.o dvb-usb-i2c.o dvb-usb-dvb.o dvb-usb-remote.o
2obj-$(CONFIG_DVB_USB) += dvb-usb.o
3
4dvb-usb-vp7045-objs = vp7045.o vp7045-fe.o
5obj-$(CONFIG_DVB_USB_VP7045) += dvb-usb-vp7045.o
6
7dvb-usb-dtt200u-objs = dtt200u.o dtt200u-fe.o
8obj-$(CONFIG_DVB_USB_DTT200U) += dvb-usb-dtt200u.o
9
10dvb-usb-dibusb-common-objs = dibusb-common.o
11
12dvb-usb-a800-objs = a800.o
13obj-$(CONFIG_DVB_USB_A800) += dvb-usb-dibusb-common.o dvb-usb-a800.o
14
15dvb-usb-dibusb-mb-objs = dibusb-mb.o
16obj-$(CONFIG_DVB_USB_DIBUSB_MB) += dvb-usb-dibusb-common.o dvb-usb-dibusb-mb.o
17
18dvb-usb-dibusb-mc-objs = dibusb-mc.o
19obj-$(CONFIG_DVB_USB_DIBUSB_MC) += dvb-usb-dibusb-common.o dvb-usb-dibusb-mc.o
20
21dvb-usb-nova-t-usb2-objs = nova-t-usb2.o
22obj-$(CONFIG_DVB_USB_NOVA_T_USB2) += dvb-usb-dibusb-common.o dvb-usb-nova-t-usb2.o
23
24dvb-usb-umt-010-objs = umt-010.o
25obj-$(CONFIG_DVB_USB_UMT_010) += dvb-usb-dibusb-common.o dvb-usb-umt-010.o
26
27dvb-usb-digitv-objs = digitv.o
28obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o
29
30EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
new file mode 100644
index 000000000000..a3542935604f
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -0,0 +1,176 @@
1/* DVB USB framework compliant Linux driver for the AVerMedia AverTV DVB-T
2 * USB2.0 (A800) DVB-T receiver.
3 *
4 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * Thanks to
7 * - AVerMedia who kindly provided information and
8 * - Glen Harris who suffered from my mistakes during development.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, version 2.
13 *
14 * see Documentation/dvb/README.dvb-usb for more information
15 */
16#include "dibusb.h"
17
18static int debug;
19module_param(debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (rc=1 (or-able))." DVB_USB_DEBUG_STATUS);
21#define deb_rc(args...) dprintk(debug,0x01,args)
22
23static int a800_power_ctrl(struct dvb_usb_device *d, int onoff)
24{
25 /* do nothing for the AVerMedia */
26 return 0;
27}
28
29static struct dvb_usb_rc_key a800_rc_keys[] = {
30 { 0x02, 0x01, KEY_PROG1 }, /* SOURCE */
31 { 0x02, 0x00, KEY_POWER }, /* POWER */
32 { 0x02, 0x05, KEY_1 }, /* 1 */
33 { 0x02, 0x06, KEY_2 }, /* 2 */
34 { 0x02, 0x07, KEY_3 }, /* 3 */
35 { 0x02, 0x09, KEY_4 }, /* 4 */
36 { 0x02, 0x0a, KEY_5 }, /* 5 */
37 { 0x02, 0x0b, KEY_6 }, /* 6 */
38 { 0x02, 0x0d, KEY_7 }, /* 7 */
39 { 0x02, 0x0e, KEY_8 }, /* 8 */
40 { 0x02, 0x0f, KEY_9 }, /* 9 */
41 { 0x02, 0x12, KEY_LEFT }, /* L / DISPLAY */
42 { 0x02, 0x11, KEY_0 }, /* 0 */
43 { 0x02, 0x13, KEY_RIGHT }, /* R / CH RTN */
44 { 0x02, 0x17, KEY_PROG2 }, /* SNAP SHOT */
45 { 0x02, 0x10, KEY_PROG3 }, /* 16-CH PREV */
46 { 0x02, 0x03, KEY_CHANNELUP }, /* CH UP */
47 { 0x02, 0x1e, KEY_VOLUMEDOWN }, /* VOL DOWN */
48 { 0x02, 0x0c, KEY_ZOOM }, /* FULL SCREEN */
49 { 0x02, 0x1f, KEY_VOLUMEUP }, /* VOL UP */
50 { 0x02, 0x02, KEY_CHANNELDOWN }, /* CH DOWN */
51 { 0x02, 0x14, KEY_MUTE }, /* MUTE */
52 { 0x02, 0x08, KEY_AUDIO }, /* AUDIO */
53 { 0x02, 0x19, KEY_RECORD }, /* RECORD */
54 { 0x02, 0x18, KEY_PLAY }, /* PLAY */
55 { 0x02, 0x1b, KEY_STOP }, /* STOP */
56 { 0x02, 0x1a, KEY_PLAYPAUSE }, /* TIMESHIFT / PAUSE */
57 { 0x02, 0x1d, KEY_BACK }, /* << / RED */
58 { 0x02, 0x1c, KEY_FORWARD }, /* >> / YELLOW */
59 { 0x02, 0x03, KEY_TEXT }, /* TELETEXT */
60 { 0x02, 0x01, KEY_FIRST }, /* |<< / GREEN */
61 { 0x02, 0x00, KEY_LAST }, /* >>| / BLUE */
62 { 0x02, 0x04, KEY_EPG }, /* EPG */
63 { 0x02, 0x15, KEY_MENU }, /* MENU */
64};
65
66int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
67{
68 u8 key[5];
69 if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0),
70 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5,
71 2*HZ) != 5)
72 return -ENODEV;
73
74 /* call the universal NEC remote processor, to find out the key's state and event */
75 dvb_usb_nec_rc_key_to_event(d,key,event,state);
76 if (key[0] != 0)
77 deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
78 return 0;
79}
80
81/* USB Driver stuff */
82static struct dvb_usb_properties a800_properties;
83
84static int a800_probe(struct usb_interface *intf,
85 const struct usb_device_id *id)
86{
87 return dvb_usb_device_init(intf,&a800_properties,THIS_MODULE);
88}
89
90/* do not change the order of the ID table */
91static struct usb_device_id a800_table [] = {
92/* 00 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_DVBT_USB2_COLD) },
93/* 01 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_DVBT_USB2_WARM) },
94 { } /* Terminating entry */
95};
96MODULE_DEVICE_TABLE (usb, a800_table);
97
98static struct dvb_usb_properties a800_properties = {
99 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
100 .pid_filter_count = 32,
101
102 .usb_ctrl = CYPRESS_FX2,
103
104 .firmware = "dvb-usb-avertv-a800-02.fw",
105
106 .size_of_priv = sizeof(struct dibusb_state),
107
108 .streaming_ctrl = dibusb2_0_streaming_ctrl,
109 .pid_filter = dibusb_pid_filter,
110 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
111 .power_ctrl = a800_power_ctrl,
112 .frontend_attach = dibusb_dib3000mc_frontend_attach,
113 .tuner_attach = dibusb_dib3000mc_tuner_attach,
114
115 .rc_interval = DEFAULT_RC_INTERVAL,
116 .rc_key_map = a800_rc_keys,
117 .rc_key_map_size = ARRAY_SIZE(a800_rc_keys),
118 .rc_query = a800_rc_query,
119
120 .i2c_algo = &dibusb_i2c_algo,
121
122 .generic_bulk_ctrl_endpoint = 0x01,
123 /* parameter for the MPEG2-data transfer */
124 .urb = {
125 .type = DVB_USB_BULK,
126 .count = 7,
127 .endpoint = 0x06,
128 .u = {
129 .bulk = {
130 .buffersize = 4096,
131 }
132 }
133 },
134
135 .num_device_descs = 1,
136 .devices = {
137 { "AVerMedia AverTV DVB-T USB 2.0 (A800)",
138 { &a800_table[0], NULL },
139 { &a800_table[1], NULL },
140 },
141 }
142};
143
144static struct usb_driver a800_driver = {
145 .owner = THIS_MODULE,
146 .name = "AVerMedia AverTV DVB-T USB 2.0 (A800)",
147 .probe = a800_probe,
148 .disconnect = dvb_usb_device_exit,
149 .id_table = a800_table,
150};
151
152/* module stuff */
153static int __init a800_module_init(void)
154{
155 int result;
156 if ((result = usb_register(&a800_driver))) {
157 err("usb_register failed. Error number %d",result);
158 return result;
159 }
160
161 return 0;
162}
163
164static void __exit a800_module_exit(void)
165{
166 /* deregister this driver from the USB subsystem */
167 usb_deregister(&a800_driver);
168}
169
170module_init (a800_module_init);
171module_exit (a800_module_exit);
172
173MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
174MODULE_DESCRIPTION("AVerMedia AverTV DVB-T USB 2.0 (A800)");
175MODULE_VERSION("1.0");
176MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
new file mode 100644
index 000000000000..63b626f70c81
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -0,0 +1,272 @@
1/* Common methods for dibusb-based-receivers.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, version 2.
8 *
9 * see Documentation/dvb/README.dvb-usb for more information
10 */
11#include "dibusb.h"
12
13static int debug;
14module_param(debug, int, 0644);
15MODULE_PARM_DESC(debug, "set debugging level (1=info (|-able))." DVB_USB_DEBUG_STATUS);
16MODULE_LICENSE("GPL");
17
18#define deb_info(args...) dprintk(debug,0x01,args)
19
20/* common stuff used by the different dibusb modules */
21int dibusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
22{
23 if (d->priv != NULL) {
24 struct dib_fe_xfer_ops *ops = d->priv;
25 if (ops->fifo_ctrl != NULL)
26 if (ops->fifo_ctrl(d->fe,onoff)) {
27 err("error while controlling the fifo of the demod.");
28 return -ENODEV;
29 }
30 }
31 return 0;
32}
33EXPORT_SYMBOL(dibusb_streaming_ctrl);
34
35int dibusb_pid_filter(struct dvb_usb_device *d, int index, u16 pid, int onoff)
36{
37 if (d->priv != NULL) {
38 struct dib_fe_xfer_ops *ops = d->priv;
39 if (d->pid_filtering && ops->pid_ctrl != NULL)
40 ops->pid_ctrl(d->fe,index,pid,onoff);
41 }
42 return 0;
43}
44EXPORT_SYMBOL(dibusb_pid_filter);
45
46int dibusb_pid_filter_ctrl(struct dvb_usb_device *d, int onoff)
47{
48 if (d->priv != NULL) {
49 struct dib_fe_xfer_ops *ops = d->priv;
50 if (ops->pid_parse != NULL)
51 if (ops->pid_parse(d->fe,onoff) < 0)
52 err("could not handle pid_parser");
53 }
54 return 0;
55}
56EXPORT_SYMBOL(dibusb_pid_filter_ctrl);
57
58int dibusb_power_ctrl(struct dvb_usb_device *d, int onoff)
59{
60 u8 b[3];
61 int ret;
62 b[0] = DIBUSB_REQ_SET_IOCTL;
63 b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
64 b[2] = onoff ? DIBUSB_IOCTL_POWER_WAKEUP : DIBUSB_IOCTL_POWER_SLEEP;
65 ret = dvb_usb_generic_write(d,b,3);
66 msleep(10);
67 return ret;
68}
69EXPORT_SYMBOL(dibusb_power_ctrl);
70
71int dibusb2_0_streaming_ctrl(struct dvb_usb_device *d, int onoff)
72{
73 u8 b[2];
74 b[0] = DIBUSB_REQ_SET_IOCTL;
75 b[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM : DIBUSB_IOCTL_CMD_DISABLE_STREAM;
76
77 dvb_usb_generic_write(d,b,3);
78
79 return dibusb_streaming_ctrl(d,onoff);
80}
81EXPORT_SYMBOL(dibusb2_0_streaming_ctrl);
82
83int dibusb2_0_power_ctrl(struct dvb_usb_device *d, int onoff)
84{
85 if (onoff) {
86 u8 b[3] = { DIBUSB_REQ_SET_IOCTL, DIBUSB_IOCTL_CMD_POWER_MODE, DIBUSB_IOCTL_POWER_WAKEUP };
87 return dvb_usb_generic_write(d,b,3);
88 } else
89 return 0;
90}
91EXPORT_SYMBOL(dibusb2_0_power_ctrl);
92
93static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr,
94 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
95{
96 u8 sndbuf[wlen+4]; /* lead(1) devaddr,direction(1) addr(2) data(wlen) (len(2) (when reading)) */
97 /* write only ? */
98 int wo = (rbuf == NULL || rlen == 0),
99 len = 2 + wlen + (wo ? 0 : 2);
100
101 sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
102 sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
103
104 memcpy(&sndbuf[2],wbuf,wlen);
105
106 if (!wo) {
107 sndbuf[wlen+2] = (rlen >> 8) & 0xff;
108 sndbuf[wlen+3] = rlen & 0xff;
109 }
110
111 return dvb_usb_generic_rw(d,sndbuf,len,rbuf,rlen,0);
112}
113
114/*
115 * I2C master xfer function
116 */
117static int dibusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
118{
119 struct dvb_usb_device *d = i2c_get_adapdata(adap);
120 int i;
121
122 if (down_interruptible(&d->i2c_sem) < 0)
123 return -EAGAIN;
124
125 if (num > 2)
126 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
127
128 for (i = 0; i < num; i++) {
129 /* write/read request */
130 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
131 if (dibusb_i2c_msg(d, msg[i].addr, msg[i].buf,msg[i].len,
132 msg[i+1].buf,msg[i+1].len) < 0)
133 break;
134 i++;
135 } else
136 if (dibusb_i2c_msg(d, msg[i].addr, msg[i].buf,msg[i].len,NULL,0) < 0)
137 break;
138 }
139
140 up(&d->i2c_sem);
141 return i;
142}
143
144static u32 dibusb_i2c_func(struct i2c_adapter *adapter)
145{
146 return I2C_FUNC_I2C;
147}
148
149struct i2c_algorithm dibusb_i2c_algo = {
150 .name = "DiBcom USB I2C algorithm",
151 .id = I2C_ALGO_BIT,
152 .master_xfer = dibusb_i2c_xfer,
153 .functionality = dibusb_i2c_func,
154};
155EXPORT_SYMBOL(dibusb_i2c_algo);
156
157int dibusb_read_eeprom_byte(struct dvb_usb_device *d, u8 offs, u8 *val)
158{
159 u8 wbuf[1] = { offs };
160 return dibusb_i2c_msg(d, 0x50, wbuf, 1, val, 1);
161}
162EXPORT_SYMBOL(dibusb_read_eeprom_byte);
163
164int dibusb_dib3000mc_frontend_attach(struct dvb_usb_device *d)
165{
166 struct dib3000_config demod_cfg;
167 struct dibusb_state *st = d->priv;
168
169 demod_cfg.pll_set = dvb_usb_pll_set_i2c;
170 demod_cfg.pll_init = dvb_usb_pll_init_i2c;
171
172 for (demod_cfg.demod_address = 0x8; demod_cfg.demod_address < 0xd; demod_cfg.demod_address++)
173 if ((d->fe = dib3000mc_attach(&demod_cfg,&d->i2c_adap,&st->ops)) != NULL) {
174 d->tuner_pass_ctrl = st->ops.tuner_pass_ctrl;
175 return 0;
176 }
177
178 return -ENODEV;
179}
180EXPORT_SYMBOL(dibusb_dib3000mc_frontend_attach);
181
182int dibusb_dib3000mc_tuner_attach (struct dvb_usb_device *d)
183{
184 d->pll_addr = 0x60;
185 d->pll_desc = &dvb_pll_env57h1xd5;
186 return 0;
187}
188EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);
189
190/*
191 * common remote control stuff
192 */
193struct dvb_usb_rc_key dibusb_rc_keys[] = {
194 /* Key codes for the little Artec T1/Twinhan/HAMA/ remote. */
195 { 0x00, 0x16, KEY_POWER },
196 { 0x00, 0x10, KEY_MUTE },
197 { 0x00, 0x03, KEY_1 },
198 { 0x00, 0x01, KEY_2 },
199 { 0x00, 0x06, KEY_3 },
200 { 0x00, 0x09, KEY_4 },
201 { 0x00, 0x1d, KEY_5 },
202 { 0x00, 0x1f, KEY_6 },
203 { 0x00, 0x0d, KEY_7 },
204 { 0x00, 0x19, KEY_8 },
205 { 0x00, 0x1b, KEY_9 },
206 { 0x00, 0x15, KEY_0 },
207 { 0x00, 0x05, KEY_CHANNELUP },
208 { 0x00, 0x02, KEY_CHANNELDOWN },
209 { 0x00, 0x1e, KEY_VOLUMEUP },
210 { 0x00, 0x0a, KEY_VOLUMEDOWN },
211 { 0x00, 0x11, KEY_RECORD },
212 { 0x00, 0x17, KEY_FAVORITES }, /* Heart symbol - Channel list. */
213 { 0x00, 0x14, KEY_PLAY },
214 { 0x00, 0x1a, KEY_STOP },
215 { 0x00, 0x40, KEY_REWIND },
216 { 0x00, 0x12, KEY_FASTFORWARD },
217 { 0x00, 0x0e, KEY_PREVIOUS }, /* Recall - Previous channel. */
218 { 0x00, 0x4c, KEY_PAUSE },
219 { 0x00, 0x4d, KEY_SCREEN }, /* Full screen mode. */
220 { 0x00, 0x54, KEY_AUDIO }, /* MTS - Switch to secondary audio. */
221 /* additional keys TwinHan VisionPlus, the Artec seemingly not have */
222 { 0x00, 0x0c, KEY_CANCEL }, /* Cancel */
223 { 0x00, 0x1c, KEY_EPG }, /* EPG */
224 { 0x00, 0x00, KEY_TAB }, /* Tab */
225 { 0x00, 0x48, KEY_INFO }, /* Preview */
226 { 0x00, 0x04, KEY_LIST }, /* RecordList */
227 { 0x00, 0x0f, KEY_TEXT }, /* Teletext */
228 /* Key codes for the KWorld/ADSTech/JetWay remote. */
229 { 0x86, 0x12, KEY_POWER },
230 { 0x86, 0x0f, KEY_SELECT }, /* source */
231 { 0x86, 0x0c, KEY_UNKNOWN }, /* scan */
232 { 0x86, 0x0b, KEY_EPG },
233 { 0x86, 0x10, KEY_MUTE },
234 { 0x86, 0x01, KEY_1 },
235 { 0x86, 0x02, KEY_2 },
236 { 0x86, 0x03, KEY_3 },
237 { 0x86, 0x04, KEY_4 },
238 { 0x86, 0x05, KEY_5 },
239 { 0x86, 0x06, KEY_6 },
240 { 0x86, 0x07, KEY_7 },
241 { 0x86, 0x08, KEY_8 },
242 { 0x86, 0x09, KEY_9 },
243 { 0x86, 0x0a, KEY_0 },
244 { 0x86, 0x18, KEY_ZOOM },
245 { 0x86, 0x1c, KEY_UNKNOWN }, /* preview */
246 { 0x86, 0x13, KEY_UNKNOWN }, /* snap */
247 { 0x86, 0x00, KEY_UNDO },
248 { 0x86, 0x1d, KEY_RECORD },
249 { 0x86, 0x0d, KEY_STOP },
250 { 0x86, 0x0e, KEY_PAUSE },
251 { 0x86, 0x16, KEY_PLAY },
252 { 0x86, 0x11, KEY_BACK },
253 { 0x86, 0x19, KEY_FORWARD },
254 { 0x86, 0x14, KEY_UNKNOWN }, /* pip */
255 { 0x86, 0x15, KEY_ESC },
256 { 0x86, 0x1a, KEY_UP },
257 { 0x86, 0x1e, KEY_DOWN },
258 { 0x86, 0x1f, KEY_LEFT },
259 { 0x86, 0x1b, KEY_RIGHT },
260};
261EXPORT_SYMBOL(dibusb_rc_keys);
262
263int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
264{
265 u8 key[5],cmd = DIBUSB_REQ_POLL_REMOTE;
266 dvb_usb_generic_rw(d,&cmd,1,key,5,0);
267 dvb_usb_nec_rc_key_to_event(d,key,event,state);
268 if (key[0] != 0)
269 deb_info("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
270 return 0;
271}
272EXPORT_SYMBOL(dibusb_rc_query);
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
new file mode 100644
index 000000000000..a0ffbb59fa14
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -0,0 +1,316 @@
1/* DVB USB compliant linux driver for mobile DVB-T USB devices based on
2 * reference designs made by DiBcom (http://www.dibcom.fr/) (DiB3000M-B)
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * based on GPL code from DiBcom, which has
7 * Copyright (C) 2004 Amaury Demol for DiBcom (ademol@dibcom.fr)
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation, version 2.
12 *
13 * see Documentation/dvb/README.dvb-usb for more information
14 */
15#include "dibusb.h"
16
17static int dibusb_dib3000mb_frontend_attach(struct dvb_usb_device *d)
18{
19 struct dib3000_config demod_cfg;
20 struct dibusb_state *st = d->priv;
21
22 demod_cfg.demod_address = 0x8;
23 demod_cfg.pll_set = dvb_usb_pll_set_i2c;
24 demod_cfg.pll_init = dvb_usb_pll_init_i2c;
25
26 if ((d->fe = dib3000mb_attach(&demod_cfg,&d->i2c_adap,&st->ops)) == NULL)
27 return -ENODEV;
28
29 d->tuner_pass_ctrl = st->ops.tuner_pass_ctrl;
30
31 return 0;
32}
33
34/* some of the dibusb 1.1 device aren't equipped with the default tuner
35 * (Thomson Cable), but with a Panasonic ENV77H11D5. This function figures
36 * this out. */
37static int dibusb_dib3000mb_tuner_attach (struct dvb_usb_device *d)
38{
39 u8 b[2] = { 0,0 }, b2[1];
40 int ret = 0;
41 struct i2c_msg msg[2] = {
42 { .flags = 0, .buf = b, .len = 2 },
43 { .flags = I2C_M_RD, .buf = b2, .len = 1 },
44 };
45
46 /* the Panasonic sits on I2C addrass 0x60, the Thomson on 0x61 */
47 msg[0].addr = msg[1].addr = 0x60;
48
49 if (d->tuner_pass_ctrl)
50 d->tuner_pass_ctrl(d->fe,1,msg[0].addr);
51
52 if (i2c_transfer (&d->i2c_adap, msg, 2) != 2) {
53 err("tuner i2c write failed.");
54 ret = -EREMOTEIO;
55 }
56
57 if (d->tuner_pass_ctrl)
58 d->tuner_pass_ctrl(d->fe,0,msg[0].addr);
59
60 if (b2[0] == 0xfe) {
61 info("this device has the Thomson Cable onboard. Which is default.");
62 d->pll_addr = 0x61;
63 d->pll_desc = &dvb_pll_tua6010xs;
64 } else {
65 u8 bpll[4] = { 0x0b, 0xf5, 0x85, 0xab };
66 info("this device has the Panasonic ENV77H11D5 onboard.");
67 d->pll_addr = 0x60;
68 memcpy(d->pll_init,bpll,4);
69 d->pll_desc = &dvb_pll_tda665x;
70 }
71
72 return ret;
73}
74
75/* USB Driver stuff */
76static struct dvb_usb_properties dibusb1_1_properties;
77static struct dvb_usb_properties dibusb1_1_an2235_properties;
78static struct dvb_usb_properties dibusb2_0b_properties;
79
80static int dibusb_probe(struct usb_interface *intf,
81 const struct usb_device_id *id)
82{
83 if (dvb_usb_device_init(intf,&dibusb1_1_properties,THIS_MODULE) == 0 ||
84 dvb_usb_device_init(intf,&dibusb1_1_an2235_properties,THIS_MODULE) == 0 ||
85 dvb_usb_device_init(intf,&dibusb2_0b_properties,THIS_MODULE) == 0)
86 return 0;
87
88 return -EINVAL;
89}
90
91/* do not change the order of the ID table */
92static struct usb_device_id dibusb_dib3000mb_table [] = {
93/* 00 */ { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_AVERMEDIA_DVBT_USB_COLD)},
94/* 01 */ { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_AVERMEDIA_DVBT_USB_WARM)},
95/* 02 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_COLD) },
96/* 03 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_WARM) },
97/* 04 */ { USB_DEVICE(USB_VID_COMPRO_UNK, USB_PID_COMPRO_DVBU2000_UNK_COLD) },
98/* 05 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3000_COLD) },
99/* 06 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3000_WARM) },
100/* 07 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_KWORLD_VSTREAM_COLD) },
101/* 08 */ { USB_DEVICE(USB_VID_EMPIA, USB_PID_KWORLD_VSTREAM_WARM) },
102/* 09 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_GRANDTEC_DVBT_USB_COLD) },
103/* 10 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_GRANDTEC_DVBT_USB_WARM) },
104/* 11 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_DIBCOM_MOD3000_COLD) },
105/* 12 */ { USB_DEVICE(USB_VID_GRANDTEC, USB_PID_DIBCOM_MOD3000_WARM) },
106/* 13 */ { USB_DEVICE(USB_VID_HYPER_PALTEK, USB_PID_UNK_HYPER_PALTEK_COLD) },
107/* 14 */ { USB_DEVICE(USB_VID_HYPER_PALTEK, USB_PID_UNK_HYPER_PALTEK_WARM) },
108/* 15 */ { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7041_COLD) },
109/* 16 */ { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7041_WARM) },
110/* 17 */ { USB_DEVICE(USB_VID_TWINHAN, USB_PID_TWINHAN_VP7041_COLD) },
111/* 18 */ { USB_DEVICE(USB_VID_TWINHAN, USB_PID_TWINHAN_VP7041_WARM) },
112/* 19 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_COLD) },
113/* 20 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_WARM) },
114/* 21 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_COLD) },
115/* 22 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_WARM) },
116/* 23 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_COLD) },
117/* 24 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_WARM) },
118 { } /* Terminating entry */
119};
120MODULE_DEVICE_TABLE (usb, dibusb_dib3000mb_table);
121
122static struct dvb_usb_properties dibusb1_1_properties = {
123 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
124 .pid_filter_count = 16,
125
126 .usb_ctrl = CYPRESS_AN2135,
127
128 .firmware = "dvb-usb-dibusb-5.0.0.11.fw",
129
130 .size_of_priv = sizeof(struct dibusb_state),
131
132 .streaming_ctrl = dibusb_streaming_ctrl,
133 .pid_filter = dibusb_pid_filter,
134 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
135 .power_ctrl = dibusb_power_ctrl,
136 .frontend_attach = dibusb_dib3000mb_frontend_attach,
137 .tuner_attach = dibusb_dib3000mb_tuner_attach,
138
139 .rc_interval = DEFAULT_RC_INTERVAL,
140 .rc_key_map = dibusb_rc_keys,
141 .rc_key_map_size = 63, /* wow, that is ugly ... I want to load it to the driver dynamically */
142 .rc_query = dibusb_rc_query,
143
144 .i2c_algo = &dibusb_i2c_algo,
145
146 .generic_bulk_ctrl_endpoint = 0x01,
147 /* parameter for the MPEG2-data transfer */
148 .urb = {
149 .type = DVB_USB_BULK,
150 .count = 7,
151 .endpoint = 0x02,
152 .u = {
153 .bulk = {
154 .buffersize = 4096,
155 }
156 }
157 },
158
159 .num_device_descs = 8,
160 .devices = {
161 { "AVerMedia AverTV DVBT USB1.1",
162 { &dibusb_dib3000mb_table[0], NULL },
163 { &dibusb_dib3000mb_table[1], NULL },
164 },
165 { "Compro Videomate DVB-U2000 - DVB-T USB1.1 (please confirm to linux-dvb)",
166 { &dibusb_dib3000mb_table[2], &dibusb_dib3000mb_table[4], NULL},
167 { &dibusb_dib3000mb_table[3], NULL },
168 },
169 { "DiBcom USB1.1 DVB-T reference design (MOD3000)",
170 { &dibusb_dib3000mb_table[5], NULL },
171 { &dibusb_dib3000mb_table[6], NULL },
172 },
173 { "KWorld V-Stream XPERT DTV - DVB-T USB1.1",
174 { &dibusb_dib3000mb_table[7], NULL },
175 { &dibusb_dib3000mb_table[8], NULL },
176 },
177 { "Grandtec USB1.1 DVB-T",
178 { &dibusb_dib3000mb_table[9], &dibusb_dib3000mb_table[11], NULL },
179 { &dibusb_dib3000mb_table[10], &dibusb_dib3000mb_table[12], NULL },
180 },
181 { "Unkown USB1.1 DVB-T device ???? please report the name to the author",
182 { &dibusb_dib3000mb_table[13], NULL },
183 { &dibusb_dib3000mb_table[14], NULL },
184 },
185 { "TwinhanDTV USB-Ter USB1.1 / Magic Box I / HAMA USB1.1 DVB-T device",
186 { &dibusb_dib3000mb_table[15], &dibusb_dib3000mb_table[17], NULL},
187 { &dibusb_dib3000mb_table[16], &dibusb_dib3000mb_table[18], NULL},
188 },
189 { "Artec T1 USB1.1 TVBOX with AN2135",
190 { &dibusb_dib3000mb_table[19], NULL },
191 { &dibusb_dib3000mb_table[20], NULL },
192 },
193 }
194};
195
196static struct dvb_usb_properties dibusb1_1_an2235_properties = {
197 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
198 .usb_ctrl = CYPRESS_AN2235,
199
200 .firmware = "dvb-usb-dibusb-an2235-01.fw",
201
202 .size_of_priv = sizeof(struct dibusb_state),
203
204 .streaming_ctrl = dibusb_streaming_ctrl,
205 .pid_filter = dibusb_pid_filter,
206 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
207 .power_ctrl = dibusb_power_ctrl,
208 .frontend_attach = dibusb_dib3000mb_frontend_attach,
209 .tuner_attach = dibusb_dib3000mb_tuner_attach,
210
211 .rc_interval = DEFAULT_RC_INTERVAL,
212 .rc_key_map = dibusb_rc_keys,
213 .rc_key_map_size = 63, /* wow, that is ugly ... I want to load it to the driver dynamically */
214 .rc_query = dibusb_rc_query,
215
216 .i2c_algo = &dibusb_i2c_algo,
217
218 .generic_bulk_ctrl_endpoint = 0x01,
219 /* parameter for the MPEG2-data transfer */
220 .urb = {
221 .type = DVB_USB_BULK,
222 .count = 7,
223 .endpoint = 0x02,
224 .u = {
225 .bulk = {
226 .buffersize = 4096,
227 }
228 }
229 },
230
231 .num_device_descs = 1,
232 .devices = {
233 { "Artec T1 USB1.1 TVBOX with AN2235",
234 { &dibusb_dib3000mb_table[20], NULL },
235 { &dibusb_dib3000mb_table[21], NULL },
236 },
237 }
238};
239
240static struct dvb_usb_properties dibusb2_0b_properties = {
241 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
242 .usb_ctrl = CYPRESS_FX2,
243
244 .firmware = "dvb-usb-adstech-usb2-01.fw",
245
246 .size_of_priv = sizeof(struct dibusb_state),
247
248 .streaming_ctrl = dibusb2_0_streaming_ctrl,
249 .pid_filter = dibusb_pid_filter,
250 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
251 .power_ctrl = dibusb2_0_power_ctrl,
252 .frontend_attach = dibusb_dib3000mb_frontend_attach,
253 .tuner_attach = dibusb_dib3000mb_tuner_attach,
254
255 .rc_interval = DEFAULT_RC_INTERVAL,
256 .rc_key_map = dibusb_rc_keys,
257 .rc_key_map_size = 63, /* wow, that is ugly ... I want to load it to the driver dynamically */
258 .rc_query = dibusb_rc_query,
259
260 .i2c_algo = &dibusb_i2c_algo,
261
262 .generic_bulk_ctrl_endpoint = 0x01,
263 /* parameter for the MPEG2-data transfer */
264 .urb = {
265 .type = DVB_USB_BULK,
266 .count = 7,
267 .endpoint = 0x06,
268 .u = {
269 .bulk = {
270 .buffersize = 4096,
271 }
272 }
273 },
274
275 .num_device_descs = 2,
276 .devices = {
277 { "KWorld/ADSTech Instant DVB-T USB 2.0",
278 { &dibusb_dib3000mb_table[23], NULL },
279 { &dibusb_dib3000mb_table[24], NULL }, /* device ID with default DIBUSB2_0-firmware */
280 },
281 }
282};
283
284static struct usb_driver dibusb_driver = {
285 .owner = THIS_MODULE,
286 .name = "DiBcom based USB DVB-T devices (DiB3000M-B based)",
287 .probe = dibusb_probe,
288 .disconnect = dvb_usb_device_exit,
289 .id_table = dibusb_dib3000mb_table,
290};
291
292/* module stuff */
293static int __init dibusb_module_init(void)
294{
295 int result;
296 if ((result = usb_register(&dibusb_driver))) {
297 err("usb_register failed. Error number %d",result);
298 return result;
299 }
300
301 return 0;
302}
303
304static void __exit dibusb_module_exit(void)
305{
306 /* deregister this driver from the USB subsystem */
307 usb_deregister(&dibusb_driver);
308}
309
310module_init (dibusb_module_init);
311module_exit (dibusb_module_exit);
312
313MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
314MODULE_DESCRIPTION("Driver for DiBcom USB DVB-T devices (DiB3000M-B based)");
315MODULE_VERSION("1.0");
316MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
new file mode 100644
index 000000000000..aad8ed3fe005
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -0,0 +1,116 @@
1/* DVB USB compliant linux driver for mobile DVB-T USB devices based on
2 * reference designs made by DiBcom (http://www.dibcom.fr/) (DiB3000M-C/P)
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * based on GPL code from DiBcom, which has
7 * Copyright (C) 2004 Amaury Demol for DiBcom (ademol@dibcom.fr)
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation, version 2.
12 *
13 * see Documentation/dvb/README.dvb-usb for more information
14 */
15#include "dibusb.h"
16
17/* USB Driver stuff */
18static struct dvb_usb_properties dibusb_mc_properties;
19
20static int dibusb_mc_probe(struct usb_interface *intf,
21 const struct usb_device_id *id)
22{
23 return dvb_usb_device_init(intf,&dibusb_mc_properties,THIS_MODULE);
24}
25
26/* do not change the order of the ID table */
27static struct usb_device_id dibusb_dib3000mc_table [] = {
28/* 00 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_COLD) },
29/* 01 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_MOD3001_WARM) },
30/* 02 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_USB2_COLD) },
31 { } /* Terminating entry */
32};
33MODULE_DEVICE_TABLE (usb, dibusb_dib3000mc_table);
34
35static struct dvb_usb_properties dibusb_mc_properties = {
36 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
37 .pid_filter_count = 32,
38
39 .usb_ctrl = CYPRESS_FX2,
40 .firmware = "dvb-usb-dibusb-6.0.0.8.fw",
41
42 .size_of_priv = sizeof(struct dibusb_state),
43
44 .streaming_ctrl = dibusb2_0_streaming_ctrl,
45 .pid_filter = dibusb_pid_filter,
46 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
47 .power_ctrl = dibusb2_0_power_ctrl,
48 .frontend_attach = dibusb_dib3000mc_frontend_attach,
49 .tuner_attach = dibusb_dib3000mc_tuner_attach,
50
51 .rc_interval = DEFAULT_RC_INTERVAL,
52 .rc_key_map = dibusb_rc_keys,
53 .rc_key_map_size = 63, /* FIXME */
54 .rc_query = dibusb_rc_query,
55
56 .i2c_algo = &dibusb_i2c_algo,
57
58 .generic_bulk_ctrl_endpoint = 0x01,
59 /* parameter for the MPEG2-data transfer */
60 .urb = {
61 .type = DVB_USB_BULK,
62 .count = 7,
63 .endpoint = 0x06,
64 .u = {
65 .bulk = {
66 .buffersize = 4096,
67 }
68 }
69 },
70
71 .num_device_descs = 2,
72 .devices = {
73 { "DiBcom USB2.0 DVB-T reference design (MOD3000P)",
74 { &dibusb_dib3000mc_table[0], NULL },
75 { &dibusb_dib3000mc_table[1], NULL },
76 },
77 { "Artec T1 USB2.0 TVBOX (please report the warm ID)",
78 { &dibusb_dib3000mc_table[2], NULL },
79 { NULL },
80 },
81 }
82};
83
84static struct usb_driver dibusb_mc_driver = {
85 .owner = THIS_MODULE,
86 .name = "DiBcom based USB2.0 DVB-T (DiB3000M-C/P based) devices",
87 .probe = dibusb_mc_probe,
88 .disconnect = dvb_usb_device_exit,
89 .id_table = dibusb_dib3000mc_table,
90};
91
92/* module stuff */
93static int __init dibusb_mc_module_init(void)
94{
95 int result;
96 if ((result = usb_register(&dibusb_mc_driver))) {
97 err("usb_register failed. Error number %d",result);
98 return result;
99 }
100
101 return 0;
102}
103
104static void __exit dibusb_mc_module_exit(void)
105{
106 /* deregister this driver from the USB subsystem */
107 usb_deregister(&dibusb_mc_driver);
108}
109
110module_init (dibusb_mc_module_init);
111module_exit (dibusb_mc_module_exit);
112
113MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
114MODULE_DESCRIPTION("Driver for DiBcom USB2.0 DVB-T (DiB3000M-C/P based) devices");
115MODULE_VERSION("1.0");
116MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dibusb.h b/drivers/media/dvb/dvb-usb/dibusb.h
new file mode 100644
index 000000000000..6611f62977c0
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dibusb.h
@@ -0,0 +1,122 @@
1/* Header file for all dibusb-based-receivers.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, version 2.
8 *
9 * see Documentation/dvb/README.dvb-usb for more information
10 */
11#ifndef _DVB_USB_DIBUSB_H_
12#define _DVB_USB_DIBUSB_H_
13
14#define DVB_USB_LOG_PREFIX "dibusb"
15#include "dvb-usb.h"
16
17#include "dib3000.h"
18
19/*
20 * protocol of all dibusb related devices
21 */
22
23/*
24 * bulk msg to/from endpoint 0x01
25 *
26 * general structure:
27 * request_byte parameter_bytes
28 */
29
30#define DIBUSB_REQ_START_READ 0x00
31#define DIBUSB_REQ_START_DEMOD 0x01
32
33/*
34 * i2c read
35 * bulk write: 0x02 ((7bit i2c_addr << 1) & 0x01) register_bytes length_word
36 * bulk read: byte_buffer (length_word bytes)
37 */
38#define DIBUSB_REQ_I2C_READ 0x02
39
40/*
41 * i2c write
42 * bulk write: 0x03 (7bit i2c_addr << 1) register_bytes value_bytes
43 */
44#define DIBUSB_REQ_I2C_WRITE 0x03
45
46/*
47 * polling the value of the remote control
48 * bulk write: 0x04
49 * bulk read: byte_buffer (5 bytes)
50 */
51#define DIBUSB_REQ_POLL_REMOTE 0x04
52
53/* additional status values for Hauppauge Remote Control Protocol */
54#define DIBUSB_RC_HAUPPAUGE_KEY_PRESSED 0x01
55#define DIBUSB_RC_HAUPPAUGE_KEY_EMPTY 0x03
56
57/* streaming mode:
58 * bulk write: 0x05 mode_byte
59 *
60 * mode_byte is mostly 0x00
61 */
62#define DIBUSB_REQ_SET_STREAMING_MODE 0x05
63
64/* interrupt the internal read loop, when blocking */
65#define DIBUSB_REQ_INTR_READ 0x06
66
67/* io control
68 * 0x07 cmd_byte param_bytes
69 *
70 * param_bytes can be up to 32 bytes
71 *
72 * cmd_byte function parameter name
73 * 0x00 power mode
74 * 0x00 sleep
75 * 0x01 wakeup
76 *
77 * 0x01 enable streaming
78 * 0x02 disable streaming
79 *
80 *
81 */
82#define DIBUSB_REQ_SET_IOCTL 0x07
83
84/* IOCTL commands */
85
86/* change the power mode in firmware */
87#define DIBUSB_IOCTL_CMD_POWER_MODE 0x00
88#define DIBUSB_IOCTL_POWER_SLEEP 0x00
89#define DIBUSB_IOCTL_POWER_WAKEUP 0x01
90
91/* modify streaming of the FX2 */
92#define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01
93#define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02
94
95struct dibusb_state {
96 struct dib_fe_xfer_ops ops;
97
98 /* for RC5 remote control */
99 int old_toggle;
100 int last_repeat_count;
101};
102
103extern struct i2c_algorithm dibusb_i2c_algo;
104
105extern int dibusb_dib3000mc_frontend_attach(struct dvb_usb_device *);
106extern int dibusb_dib3000mc_tuner_attach (struct dvb_usb_device *);
107
108extern int dibusb_streaming_ctrl(struct dvb_usb_device *, int);
109extern int dibusb_pid_filter(struct dvb_usb_device *, int, u16, int);
110extern int dibusb_pid_filter_ctrl(struct dvb_usb_device *, int);
111extern int dibusb_power_ctrl(struct dvb_usb_device *, int);
112extern int dibusb2_0_streaming_ctrl(struct dvb_usb_device *, int);
113extern int dibusb2_0_power_ctrl(struct dvb_usb_device *, int);
114
115#define DEFAULT_RC_INTERVAL 150
116//#define DEFAULT_RC_INTERVAL 100000
117
118extern struct dvb_usb_rc_key dibusb_rc_keys[];
119extern int dibusb_rc_query(struct dvb_usb_device *, u32 *, int *);
120extern int dibusb_read_eeprom_byte(struct dvb_usb_device *, u8, u8 *);
121
122#endif
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
new file mode 100644
index 000000000000..5acf3fde9522
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -0,0 +1,282 @@
1/* DVB USB compliant linux driver for Nebula Electronics uDigiTV DVB-T USB2.0
2 * receiver
3 *
4 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de) and
5 * Allan Third (allan.third@cs.man.ac.uk)
6 *
7 * partly based on the SDK published by Nebula Electronics (TODO do we want this line ?)
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation, version 2.
12 *
13 * see Documentation/dvb/README.dvb-usb for more information
14 */
15#include "digitv.h"
16
17#include "mt352.h"
18#include "nxt6000.h"
19
20/* debug */
21int dvb_usb_digitv_debug;
22module_param_named(debug,dvb_usb_digitv_debug, int, 0644);
23MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
24
25static int digitv_ctrl_msg(struct dvb_usb_device *d,
26 u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
27{
28 int wo = (rbuf == NULL || rlen == 0); /* write-only */
29 u8 sndbuf[7],rcvbuf[7];
30 memset(sndbuf,0,7); memset(rcvbuf,0,7);
31
32 sndbuf[0] = cmd;
33 sndbuf[1] = vv;
34 sndbuf[2] = wo ? wlen : rlen;
35
36 if (!wo) {
37 memcpy(&sndbuf[3],wbuf,wlen);
38 dvb_usb_generic_write(d,sndbuf,7);
39 } else {
40 dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10);
41 memcpy(&rbuf,&rcvbuf[3],rlen);
42 }
43 return 0;
44}
45
46/* I2C */
47static int digitv_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
48{
49 struct dvb_usb_device *d = i2c_get_adapdata(adap);
50 int i;
51
52 if (down_interruptible(&d->i2c_sem) < 0)
53 return -EAGAIN;
54
55 if (num > 2)
56 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
57
58 for (i = 0; i < num; i++) {
59 /* write/read request */
60 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
61 if (digitv_ctrl_msg(d, USB_READ_COFDM, msg[i].buf[0], NULL, 0,
62 msg[i+1].buf,msg[i+1].len) < 0)
63 break;
64 i++;
65 } else
66 if (digitv_ctrl_msg(d,USB_WRITE_COFDM, msg[i].buf[0],
67 &msg[i].buf[1],msg[i].len-1,NULL,0) < 0)
68 break;
69 }
70
71 up(&d->i2c_sem);
72 return i;
73}
74
75static u32 digitv_i2c_func(struct i2c_adapter *adapter)
76{
77 return I2C_FUNC_I2C;
78}
79
80static struct i2c_algorithm digitv_i2c_algo = {
81 .name = "Nebula DigiTV USB I2C algorithm",
82 .id = I2C_ALGO_BIT,
83 .master_xfer = digitv_i2c_xfer,
84 .functionality = digitv_i2c_func,
85};
86
87/* Callbacks for DVB USB */
88static int digitv_identify_state (struct usb_device *udev, struct
89 dvb_usb_properties *props, struct dvb_usb_device_description **desc,
90 int *cold)
91{
92 *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;
93 return 0;
94}
95
96static int digitv_mt352_demod_init(struct dvb_frontend *fe)
97{
98 static u8 mt352_clock_config[] = { 0x89, 0x38, 0x2d };
99 static u8 mt352_reset[] = { 0x50, 0x80 };
100 static u8 mt352_mclk_ratio[] = { 0x8b, 0x00 };
101
102 static u8 mt352_agc_cfg[] = { 0x68, 0xa0 };
103 static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0xa0 };
104 static u8 mt352_acq_ctl[] = { 0x53, 0x50 };
105 static u8 mt352_agc_target[] = { 0x67, 0x20 };
106
107 static u8 mt352_rs_err_per[] = { 0x7c, 0x00, 0x01 };
108 static u8 mt352_snr_select[] = { 0x79, 0x00, 0x20 };
109
110 static u8 mt352_input_freq_1[] = { 0x56, 0x31, 0x05 };
111
112 static u8 mt352_scan_ctl[] = { 0x88, 0x0f };
113 static u8 mt352_capt_range[] = { 0x75, 0x32 };
114
115 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
116 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
117 msleep(1);
118 mt352_write(fe, mt352_mclk_ratio, sizeof(mt352_mclk_ratio));
119
120 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
121 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
122 mt352_write(fe, mt352_acq_ctl, sizeof(mt352_acq_ctl));
123 mt352_write(fe, mt352_agc_target, sizeof(mt352_agc_target));
124
125
126 mt352_write(fe, mt352_rs_err_per, sizeof(mt352_rs_err_per));
127 mt352_write(fe, mt352_snr_select, sizeof(mt352_snr_select));
128
129 mt352_write(fe, mt352_input_freq_1, sizeof(mt352_input_freq_1));
130
131 mt352_write(fe, mt352_scan_ctl, sizeof(mt352_scan_ctl));
132 mt352_write(fe, mt352_capt_range, sizeof(mt352_capt_range));
133
134 return 0;
135}
136
137static struct mt352_config digitv_mt352_config = {
138 .demod_address = 0x0, /* ignored by the digitv anyway */
139 .demod_init = digitv_mt352_demod_init,
140 .pll_set = NULL, /* TODO */
141};
142
143static struct nxt6000_config digitv_nxt6000_config = {
144 .demod_address = 0x0, /* ignored by the digitv anyway */
145 .clock_inversion = 0x0,
146
147 .pll_init = NULL,
148 .pll_set = NULL,
149};
150
151static int digitv_frontend_attach(struct dvb_usb_device *d)
152{
153 if ((d->fe = mt352_attach(&digitv_mt352_config, &d->i2c_adap)) == NULL)
154 return 0;
155 if ((d->fe = nxt6000_attach(&digitv_nxt6000_config, &d->i2c_adap)) == NULL) {
156
157 warn("nxt6000 support is not done yet, in fact you are one of the first "
158 "person who wants to use this device in Linux. Please report to "
159 "linux-dvb@linuxtv.org");
160
161 return 0;
162 }
163 return -EIO;
164}
165
166static struct dvb_usb_rc_key digitv_rc_keys[] = {
167 { 0x00, 0x16, KEY_POWER }, /* dummy key */
168};
169
170/* TODO is it really the NEC protocol ? */
171int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
172{
173 u8 key[5];
174
175 digitv_ctrl_msg(d,USB_READ_REMOTE,0,NULL,0,&key[1],4);
176 /* TODO state, maybe it is VV ? */
177 if (key[1] != 0)
178 key[0] = 0x01; /* if something is inside the buffer, simulate key press */
179
180 /* call the universal NEC remote processor, to find out the key's state and event */
181 dvb_usb_nec_rc_key_to_event(d,key,event,state);
182 if (key[0] != 0)
183 deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
184 return 0;
185}
186
187
188/* DVB USB Driver stuff */
189static struct dvb_usb_properties digitv_properties;
190
191static int digitv_probe(struct usb_interface *intf,
192 const struct usb_device_id *id)
193{
194 return dvb_usb_device_init(intf,&digitv_properties,THIS_MODULE);
195}
196
197static struct usb_device_id digitv_table [] = {
198 { USB_DEVICE(USB_VID_ANCHOR, USB_PID_NEBULA_DIGITV) },
199 { } /* Terminating entry */
200};
201MODULE_DEVICE_TABLE (usb, digitv_table);
202
203static struct dvb_usb_properties digitv_properties = {
204 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
205
206 .usb_ctrl = CYPRESS_FX2,
207 .firmware = "dvb-usb-digitv-01.fw",
208
209 .size_of_priv = 0,
210
211 .streaming_ctrl = NULL,
212 .pid_filter = NULL,
213 .pid_filter_ctrl = NULL,
214 .power_ctrl = NULL,
215 .frontend_attach = digitv_frontend_attach,
216 .tuner_attach = NULL, // digitv_tuner_attach,
217 .read_mac_address = NULL,
218
219 .rc_interval = 1000,
220 .rc_key_map = digitv_rc_keys,
221 .rc_key_map_size = ARRAY_SIZE(digitv_rc_keys),
222 .rc_query = digitv_rc_query,
223
224 .identify_state = digitv_identify_state,
225
226 .i2c_algo = &digitv_i2c_algo,
227
228 .generic_bulk_ctrl_endpoint = 0x01,
229 /* parameter for the MPEG2-data transfer */
230 .urb = {
231 .type = DVB_USB_BULK,
232 .count = 7,
233 .endpoint = 0x02,
234 .u = {
235 .bulk = {
236 .buffersize = 4096,
237 }
238 }
239 },
240
241 .num_device_descs = 2,
242 .devices = {
243 { "Nebula Electronics uDigiTV DVB-T USB2.0)",
244 { &digitv_table[0], NULL },
245 { NULL },
246 },
247 }
248};
249
250static struct usb_driver digitv_driver = {
251 .owner = THIS_MODULE,
252 .name = "Nebula Electronics uDigiTV DVB-T USB2.0 device",
253 .probe = digitv_probe,
254 .disconnect = dvb_usb_device_exit,
255 .id_table = digitv_table,
256};
257
258/* module stuff */
259static int __init digitv_module_init(void)
260{
261 int result;
262 if ((result = usb_register(&digitv_driver))) {
263 err("usb_register failed. Error number %d",result);
264 return result;
265 }
266
267 return 0;
268}
269
270static void __exit digitv_module_exit(void)
271{
272 /* deregister this driver from the USB subsystem */
273 usb_deregister(&digitv_driver);
274}
275
276module_init (digitv_module_init);
277module_exit (digitv_module_exit);
278
279MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
280MODULE_DESCRIPTION("Driver for Nebula Electronics uDigiTV DVB-T USB2.0");
281MODULE_VERSION("1.0-alpha");
282MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/digitv.h b/drivers/media/dvb/dvb-usb/digitv.h
new file mode 100644
index 000000000000..477ee428a70e
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/digitv.h
@@ -0,0 +1,65 @@
1#ifndef _DVB_USB_DIGITV_H_
2#define _DVB_USB_DIGITV_H_
3
4#define DVB_USB_LOG_PREFIX "digitv"
5#include "dvb-usb.h"
6
7extern int dvb_usb_digitv_debug;
8#define deb_rc(args...) dprintk(dvb_usb_digitv_debug,0x01,args)
9
10/* protocol (from usblogging and the SDK:
11 *
12 * Always 7 bytes bulk message(s) for controlling
13 *
14 * First byte describes the command. Reads are 2 consecutive transfer (as always).
15 *
16 * General structure:
17 *
18 * write or first message of a read:
19 * <cmdbyte> VV <len> B0 B1 B2 B3
20 *
21 * second message of a read
22 * <cmdbyte> VV <len> R0 R1 R2 R3
23 *
24 * whereas 0 < len <= 4
25 *
26 * I2C address is stored somewhere inside the device.
27 *
28 * 0x01 read from EEPROM
29 * VV = offset; B* = 0; R* = value(s)
30 *
31 * 0x02 read register of the COFDM
32 * VV = register; B* = 0; R* = value(s)
33 *
34 * 0x05 write register of the COFDM
35 * VV = register; B* = value(s);
36 *
37 * 0x06 write to the tuner (only for NXT6000)
38 * VV = 0; B* = PLL data; len = 4;
39 *
40 * 0x03 read remote control
41 * VV = 0; B* = 0; len = 4; R* = key
42 *
43 * 0x07 write to the remote (don't know why one should this, resetting ?)
44 * VV = 0; B* = key; len = 4;
45 *
46 * 0x08 write remote type
47 * VV = 0; B[0] = 0x01, len = 4
48 *
49 * 0x09 write device init
50 * TODO
51 */
52#define USB_READ_EEPROM 1
53
54#define USB_READ_COFDM 2
55#define USB_WRITE_COFDM 5
56
57#define USB_WRITE_TUNER 6
58
59#define USB_READ_REMOTE 3
60#define USB_WRITE_REMOTE 7
61#define USB_WRITE_REMOTE_TYPE 8
62
63#define USB_DEV_INIT 9
64
65#endif
diff --git a/drivers/media/dvb/dibusb/dvb-fe-dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
index 1872aa6d200a..d17d768038c6 100644
--- a/drivers/media/dvb/dibusb/dvb-fe-dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
@@ -1,42 +1,18 @@
1/* 1/* Frontend part of the Linux driver for the Yakumo/Hama/Typhoon DVB-T
2 * dvb-dtt200u-fe.c is a driver which implements the frontend-part of the 2 * USB2.0 receiver.
3 * Yakumo/Typhoon/Hama USB2.0 boxes. It is hard-wired to the dibusb-driver as
4 * it uses the usb-transfer functions directly (maybe creating a
5 * generic-dvb-usb-lib for all usb-drivers will be reduce some more code.)
6 * 3 *
7 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de> 4 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de>
8 * 5 *
9 * see dvb-dibusb-core.c for copyright details. 6 * This program is free software; you can redistribute it and/or modify it
10 */ 7 * under the terms of the GNU General Public License as published by the Free
11 8 * Software Foundation, version 2.
12/* guessed protocol description (reverse engineered):
13 * read
14 * 00 - USB type 0x02 for usb2.0, 0x01 for usb1.1
15 * 81 - <TS_LOCK> <current frequency divided by 250000>
16 * 82 - crash - do not touch
17 * 83 - crash - do not touch
18 * 84 - remote control
19 * 85 - crash - do not touch (OK, stop testing here)
20 * 88 - locking 2 bytes (0x80 0x40 == no signal, 0x89 0x20 == nice signal)
21 * 89 - noise-to-signal
22 * 8a - unkown 1 byte - signal_strength
23 * 8c - ber ???
24 * 8d - ber
25 * 8e - unc
26 * 9 *
27 * write 10 * see Documentation/dvb/README.dvb-usb for more information
28 * 02 - bandwidth
29 * 03 - frequency (divided by 250000)
30 * 04 - pid table (index pid(7:0) pid(12:8))
31 * 05 - reset the pid table
32 * 08 - demod transfer enabled or not (FX2 transfer is enabled by default)
33 */ 11 */
34 12#include "dtt200u.h"
35#include "dvb-dibusb.h"
36#include "dvb_frontend.h"
37 13
38struct dtt200u_fe_state { 14struct dtt200u_fe_state {
39 struct usb_dibusb *dib; 15 struct dvb_usb_device *d;
40 16
41 struct dvb_frontend_parameters fep; 17 struct dvb_frontend_parameters fep;
42 struct dvb_frontend frontend; 18 struct dvb_frontend frontend;
@@ -47,11 +23,11 @@ struct dtt200u_fe_state {
47static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat) 23static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat)
48{ 24{
49 struct dtt200u_fe_state *state = fe->demodulator_priv; 25 struct dtt200u_fe_state *state = fe->demodulator_priv;
50 u8 bw[1] = { 0x81 }; 26 u8 bw = GET_TUNE_STAT;
51 u8 br[3] = { 0 }; 27 u8 br[3] = { 0 };
52// u8 bdeb[5] = { 0 }; 28// u8 bdeb[5] = { 0 };
53 29
54 dibusb_readwrite_usb(state->dib,bw,1,br,3); 30 dvb_usb_generic_rw(state->d,&bw,1,br,3,0);
55 switch (br[0]) { 31 switch (br[0]) {
56 case 0x01: 32 case 0x01:
57 *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 33 *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
@@ -60,12 +36,12 @@ static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat)
60 *stat = 0; 36 *stat = 0;
61 break; 37 break;
62 default: 38 default:
63 moan("br[0]",0x81); 39 moan("br[0]",GET_TUNE_STAT);
64 break; 40 break;
65 } 41 }
66 42
67// bw[0] = 0x88; 43// bw[0] = 0x88;
68// dibusb_readwrite_usb(state->dib,bw,1,bdeb,5); 44// dvb_usb_generic_rw(state->d,bw,1,bdeb,5,0);
69 45
70// deb_info("%02x: %02x %02x %02x %02x %02x\n",bw[0],bdeb[0],bdeb[1],bdeb[2],bdeb[3],bdeb[4]); 46// deb_info("%02x: %02x %02x %02x %02x %02x\n",bw[0],bdeb[0],bdeb[1],bdeb[2],bdeb[3],bdeb[4]);
71 47
@@ -74,27 +50,26 @@ static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat)
74static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber) 50static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
75{ 51{
76 struct dtt200u_fe_state *state = fe->demodulator_priv; 52 struct dtt200u_fe_state *state = fe->demodulator_priv;
77 u8 bw[1] = { 0x8d }; 53 u8 bw = GET_BER;
78 *ber = 0; 54 *ber = 0;
79 dibusb_readwrite_usb(state->dib,bw,1,(u8*) ber, 3); 55 dvb_usb_generic_rw(state->d,&bw,1,(u8*) ber,3,0);
80 return 0; 56 return 0;
81} 57}
82 58
83static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) 59static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
84{ 60{
85 struct dtt200u_fe_state *state = fe->demodulator_priv; 61 struct dtt200u_fe_state *state = fe->demodulator_priv;
86 u8 bw[1] = { 0x8c }; 62 u8 bw = GET_UNK;
87 *unc = 0; 63 *unc = 0;
88 dibusb_readwrite_usb(state->dib,bw,1,(u8*) unc, 3); 64 dvb_usb_generic_rw(state->d,&bw,1,(u8*) unc,3,0);
89 return 0; 65 return 0;
90} 66}
91 67
92static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) 68static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
93{ 69{
94 struct dtt200u_fe_state *state = fe->demodulator_priv; 70 struct dtt200u_fe_state *state = fe->demodulator_priv;
95 u8 bw[1] = { 0x8a }; 71 u8 bw = GET_SIG_STRENGTH, b;
96 u8 b; 72 dvb_usb_generic_rw(state->d,&bw,1,&b,1,0);
97 dibusb_readwrite_usb(state->dib,bw,1,&b, 1);
98 *strength = (b << 8) | b; 73 *strength = (b << 8) | b;
99 return 0; 74 return 0;
100} 75}
@@ -102,18 +77,17 @@ static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strengt
102static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr) 77static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
103{ 78{
104 struct dtt200u_fe_state *state = fe->demodulator_priv; 79 struct dtt200u_fe_state *state = fe->demodulator_priv;
105 u8 bw[1] = { 0x89 }; 80 u8 bw = GET_SNR,br;
106 u8 br[1] = { 0 }; 81 dvb_usb_generic_rw(state->d,&bw,1,&br,1,0);
107 dibusb_readwrite_usb(state->dib,bw,1,br,1); 82 *snr = ~((br << 8) | br);
108 *snr = ((0xff - br[0]) << 8) | (0xff - br[0]);
109 return 0; 83 return 0;
110} 84}
111 85
112static int dtt200u_fe_init(struct dvb_frontend* fe) 86static int dtt200u_fe_init(struct dvb_frontend* fe)
113{ 87{
114 struct dtt200u_fe_state *state = fe->demodulator_priv; 88 struct dtt200u_fe_state *state = fe->demodulator_priv;
115 u8 b[] = { 0x01 }; 89 u8 b = RESET_DEMOD;
116 return dibusb_write_usb(state->dib,b,1); 90 return dvb_usb_generic_write(state->d,&b,1);
117} 91}
118 92
119static int dtt200u_fe_sleep(struct dvb_frontend* fe) 93static int dtt200u_fe_sleep(struct dvb_frontend* fe)
@@ -134,7 +108,7 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend* fe,
134{ 108{
135 struct dtt200u_fe_state *state = fe->demodulator_priv; 109 struct dtt200u_fe_state *state = fe->demodulator_priv;
136 u16 freq = fep->frequency / 250000; 110 u16 freq = fep->frequency / 250000;
137 u8 bw,bwbuf[2] = { 0x03, 0 }, freqbuf[3] = { 0x02, 0, 0 }; 111 u8 bw,bwbuf[2] = { SET_BANDWIDTH, 0 }, freqbuf[3] = { SET_FREQUENCY, 0, 0 };
138 112
139 switch (fep->u.ofdm.bandwidth) { 113 switch (fep->u.ofdm.bandwidth) {
140 case BANDWIDTH_8_MHZ: bw = 8; break; 114 case BANDWIDTH_8_MHZ: bw = 8; break;
@@ -147,11 +121,11 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend* fe,
147 deb_info("set_frontend\n"); 121 deb_info("set_frontend\n");
148 122
149 bwbuf[1] = bw; 123 bwbuf[1] = bw;
150 dibusb_write_usb(state->dib,bwbuf,2); 124 dvb_usb_generic_write(state->d,bwbuf,2);
151 125
152 freqbuf[1] = freq & 0xff; 126 freqbuf[1] = freq & 0xff;
153 freqbuf[2] = (freq >> 8) & 0xff; 127 freqbuf[2] = (freq >> 8) & 0xff;
154 dibusb_write_usb(state->dib,freqbuf,3); 128 dvb_usb_generic_write(state->d,freqbuf,3);
155 129
156 memcpy(&state->fep,fep,sizeof(struct dvb_frontend_parameters)); 130 memcpy(&state->fep,fep,sizeof(struct dvb_frontend_parameters));
157 131
@@ -172,37 +146,9 @@ static void dtt200u_fe_release(struct dvb_frontend* fe)
172 kfree(state); 146 kfree(state);
173} 147}
174 148
175static int dtt200u_pid_control(struct dvb_frontend *fe,int index, int pid,int onoff)
176{
177 struct dtt200u_fe_state *state = (struct dtt200u_fe_state*) fe->demodulator_priv;
178 u8 b_pid[4];
179 pid = onoff ? pid : 0;
180
181 b_pid[0] = 0x04;
182 b_pid[1] = index;
183 b_pid[2] = pid & 0xff;
184 b_pid[3] = (pid >> 8) & 0xff;
185
186 dibusb_write_usb(state->dib,b_pid,4);
187 return 0;
188}
189
190static int dtt200u_fifo_control(struct dvb_frontend *fe, int onoff)
191{
192 struct dtt200u_fe_state *state = (struct dtt200u_fe_state*) fe->demodulator_priv;
193 u8 b_streaming[2] = { 0x08, onoff };
194 u8 b_rst_pid[1] = { 0x05 };
195
196 dibusb_write_usb(state->dib,b_streaming,2);
197
198 if (!onoff)
199 dibusb_write_usb(state->dib,b_rst_pid,1);
200 return 0;
201}
202
203static struct dvb_frontend_ops dtt200u_fe_ops; 149static struct dvb_frontend_ops dtt200u_fe_ops;
204 150
205struct dvb_frontend* dtt200u_fe_attach(struct usb_dibusb *dib, struct dib_fe_xfer_ops *xfer_ops) 151struct dvb_frontend* dtt200u_fe_attach(struct dvb_usb_device *d)
206{ 152{
207 struct dtt200u_fe_state* state = NULL; 153 struct dtt200u_fe_state* state = NULL;
208 154
@@ -214,14 +160,11 @@ struct dvb_frontend* dtt200u_fe_attach(struct usb_dibusb *dib, struct dib_fe_xfe
214 160
215 deb_info("attaching frontend dtt200u\n"); 161 deb_info("attaching frontend dtt200u\n");
216 162
217 state->dib = dib; 163 state->d = d;
218 164
219 state->frontend.ops = &dtt200u_fe_ops; 165 state->frontend.ops = &dtt200u_fe_ops;
220 state->frontend.demodulator_priv = state; 166 state->frontend.demodulator_priv = state;
221 167
222 xfer_ops->fifo_ctrl = dtt200u_fifo_control;
223 xfer_ops->pid_ctrl = dtt200u_pid_control;
224
225 goto success; 168 goto success;
226error: 169error:
227 return NULL; 170 return NULL;
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
new file mode 100644
index 000000000000..fb2b5a2da137
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -0,0 +1,171 @@
1/* DVB USB library compliant Linux driver for the Yakumo/Hama/Typhoon DVB-T
2 * USB2.0 receiver.
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
9 *
10 * see Documentation/dvb/README.dvb-usb for more information
11 */
12#include "dtt200u.h"
13
14/* debug */
15int dvb_usb_dtt200u_debug;
16module_param_named(debug,dvb_usb_dtt200u_debug, int, 0644);
17MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 (or-able))." DVB_USB_DEBUG_STATUS);
18
19static int dtt200u_streaming_ctrl(struct dvb_usb_device *d, int onoff)
20{
21 u8 b_streaming[2] = { SET_TS_CTRL, onoff };
22 u8 b_rst_pid = RESET_PID_FILTER;
23
24 dvb_usb_generic_write(d,b_streaming,2);
25
26 if (!onoff)
27 dvb_usb_generic_write(d,&b_rst_pid,1);
28 return 0;
29}
30
31static int dtt200u_pid_filter(struct dvb_usb_device *d, int index, u16 pid, int onoff)
32{
33 u8 b_pid[4];
34 pid = onoff ? pid : 0;
35
36 b_pid[0] = SET_PID_FILTER;
37 b_pid[1] = index;
38 b_pid[2] = pid & 0xff;
39 b_pid[3] = (pid >> 8) & 0xff;
40
41 return dvb_usb_generic_write(d,b_pid,4);
42}
43
44/* remote control */
45/* key list for the tiny remote control (Yakumo, don't know about the others) */
46static struct dvb_usb_rc_key dtt200u_rc_keys[] = {
47 { 0x80, 0x01, KEY_MUTE },
48 { 0x80, 0x02, KEY_CHANNELDOWN },
49 { 0x80, 0x03, KEY_VOLUMEDOWN },
50 { 0x80, 0x04, KEY_1 },
51 { 0x80, 0x05, KEY_2 },
52 { 0x80, 0x06, KEY_3 },
53 { 0x80, 0x07, KEY_4 },
54 { 0x80, 0x08, KEY_5 },
55 { 0x80, 0x09, KEY_6 },
56 { 0x80, 0x0a, KEY_7 },
57 { 0x00, 0x0c, KEY_ZOOM },
58 { 0x80, 0x0d, KEY_0 },
59 { 0x00, 0x0e, KEY_SELECT },
60 { 0x80, 0x12, KEY_POWER },
61 { 0x80, 0x1a, KEY_CHANNELUP },
62 { 0x80, 0x1b, KEY_8 },
63 { 0x80, 0x1e, KEY_VOLUMEUP },
64 { 0x80, 0x1f, KEY_9 },
65};
66
67static int dtt200u_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
68{
69 u8 key[5],cmd = GET_RC_KEY;
70 dvb_usb_generic_rw(d,&cmd,1,key,5,0);
71 dvb_usb_nec_rc_key_to_event(d,key,event,state);
72 if (key[0] != 0)
73 deb_info("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
74 return 0;
75}
76
77static int dtt200u_frontend_attach(struct dvb_usb_device *d)
78{
79 d->fe = dtt200u_fe_attach(d);
80 return 0;
81}
82
83static struct dvb_usb_properties dtt200u_properties;
84
85static int dtt200u_usb_probe(struct usb_interface *intf,
86 const struct usb_device_id *id)
87{
88 return dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE);
89}
90
91static struct usb_device_id dtt200u_usb_table [] = {
92 { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_DTT200U_COLD) },
93 { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_DTT200U_WARM) },
94 { 0 },
95};
96MODULE_DEVICE_TABLE(usb, dtt200u_usb_table);
97
98static struct dvb_usb_properties dtt200u_properties = {
99 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING,
100 .pid_filter_count = 255, /* It is a guess, but there are at least 10 */
101
102 .usb_ctrl = CYPRESS_FX2,
103 .firmware = "dvb-usb-dtt200u-01.fw",
104
105 .streaming_ctrl = dtt200u_streaming_ctrl,
106 .pid_filter = dtt200u_pid_filter,
107 .frontend_attach = dtt200u_frontend_attach,
108
109 .rc_interval = 200,
110 .rc_key_map = dtt200u_rc_keys,
111 .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
112 .rc_query = dtt200u_rc_query,
113
114 .generic_bulk_ctrl_endpoint = 0x01,
115
116 /* parameter for the MPEG2-data transfer */
117 .urb = {
118 .type = DVB_USB_BULK,
119 .count = 7,
120 .endpoint = 0x02,
121 .u = {
122 .bulk = {
123 .buffersize = 4096,
124 }
125 }
126 },
127
128 .num_device_descs = 1,
129 .devices = {
130 { .name = "Yakumo/Hama/Typhoon DVB-T USB2.0)",
131 .cold_ids = { &dtt200u_usb_table[0], &dtt200u_usb_table[2] },
132 .warm_ids = { &dtt200u_usb_table[1], NULL },
133 },
134 { 0 },
135 }
136};
137
138/* usb specific object needed to register this driver with the usb subsystem */
139static struct usb_driver dtt200u_usb_driver = {
140 .owner = THIS_MODULE,
141 .name = "Yakumo/Hama/Typhoon DVB-T USB2.0",
142 .probe = dtt200u_usb_probe,
143 .disconnect = dvb_usb_device_exit,
144 .id_table = dtt200u_usb_table,
145};
146
147/* module stuff */
148static int __init dtt200u_usb_module_init(void)
149{
150 int result;
151 if ((result = usb_register(&dtt200u_usb_driver))) {
152 err("usb_register failed. (%d)",result);
153 return result;
154 }
155
156 return 0;
157}
158
159static void __exit dtt200u_usb_module_exit(void)
160{
161 /* deregister this driver from the USB subsystem */
162 usb_deregister(&dtt200u_usb_driver);
163}
164
165module_init(dtt200u_usb_module_init);
166module_exit(dtt200u_usb_module_exit);
167
168MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
169MODULE_DESCRIPTION("Driver for the Yakumo/Hama/Typhoon DVB-T USB2.0 device");
170MODULE_VERSION("1.0");
171MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.h b/drivers/media/dvb/dvb-usb/dtt200u.h
new file mode 100644
index 000000000000..ed4142071518
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dtt200u.h
@@ -0,0 +1,66 @@
1/* Common header file of Linux driver for the Yakumo/Hama/Typhoon DVB-T
2 * USB2.0 receiver.
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
9 *
10 * see Documentation/dvb/README.dvb-usb for more information
11 */
12#ifndef _DVB_USB_DTT200U_H_
13#define _DVB_USB_DTT200U_H_
14
15#define DVB_USB_LOG_PREFIX "dtt200u"
16#include "dvb-usb.h"
17
18extern int dvb_usb_dtt200u_debug;
19#define deb_info(args...) dprintk(dvb_usb_dtt200u_debug,0x01,args)
20#define deb_xfer(args...) dprintk(dvb_usb_dtt200u_debug,0x02,args)
21
22/* guessed protocol description (reverse engineered):
23 * read
24 * 00 - USB type 0x02 for usb2.0, 0x01 for usb1.1
25 * 81 - <TS_LOCK> <current frequency divided by 250000>
26 * 82 - crash - do not touch
27 * 83 - crash - do not touch
28 * 84 - remote control
29 * 85 - crash - do not touch (OK, stop testing here)
30 * 88 - locking 2 bytes (0x80 0x40 == no signal, 0x89 0x20 == nice signal)
31 * 89 - noise-to-signal
32 * 8a - unkown 1 byte - signal_strength
33 * 8c - ber ???
34 * 8d - ber
35 * 8e - unc
36 */
37
38#define GET_SPEED 0x00
39#define GET_TUNE_STAT 0x81
40#define GET_RC_KEY 0x84
41#define GET_STATUS 0x88
42#define GET_SNR 0x89
43#define GET_SIG_STRENGTH 0x8a
44#define GET_UNK 0x8c
45#define GET_BER 0x8d
46#define GET_UNC 0x8e
47
48/* write
49 * 01 - reset the demod
50 * 02 - frequency (divided by 250000)
51 * 03 - bandwidth
52 * 04 - pid table (index pid(7:0) pid(12:8))
53 * 05 - reset the pid table
54 * 08 - demod transfer enabled or not (FX2 transfer is enabled by default)
55 */
56
57#define RESET_DEMOD 0x01
58#define SET_FREQUENCY 0x02
59#define SET_BANDWIDTH 0x03
60#define SET_PID_FILTER 0x04
61#define RESET_PID_FILTER 0x05
62#define SET_TS_CTRL 0x08
63
64extern struct dvb_frontend * dtt200u_fe_attach(struct dvb_usb_device *d);
65
66#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-common.h b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
new file mode 100644
index 000000000000..67e0d73fbceb
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
@@ -0,0 +1,44 @@
1/* dvb-usb-common.h is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
5 *
6 * a header file containing prototypes and types for internal use of the dvb-usb-lib
7 */
8#ifndef _DVB_USB_COMMON_H_
9#define _DVB_USB_COMMON_H_
10
11#define DVB_USB_LOG_PREFIX "dvb-usb"
12#include "dvb-usb.h"
13
14extern int dvb_usb_debug;
15
16#define deb_info(args...) dprintk(dvb_usb_debug,0x01,args)
17#define deb_xfer(args...) dprintk(dvb_usb_debug,0x02,args)
18#define deb_pll(args...) dprintk(dvb_usb_debug,0x04,args)
19#define deb_ts(args...) dprintk(dvb_usb_debug,0x08,args)
20#define deb_err(args...) dprintk(dvb_usb_debug,0x10,args)
21#define deb_rc(args...) dprintk(dvb_usb_debug,0x20,args)
22#define deb_fw(args...) dprintk(dvb_usb_debug,0x40,args)
23
24/* commonly used methods */
25extern int usb_cypress_load_firmware(struct usb_device *, const char *, int);
26
27extern int dvb_usb_urb_submit(struct dvb_usb_device *);
28extern int dvb_usb_urb_kill(struct dvb_usb_device *);
29extern int dvb_usb_urb_init(struct dvb_usb_device *);
30extern int dvb_usb_urb_exit(struct dvb_usb_device *);
31
32extern int dvb_usb_i2c_init(struct dvb_usb_device *);
33extern int dvb_usb_i2c_exit(struct dvb_usb_device *);
34
35extern int dvb_usb_dvb_init(struct dvb_usb_device *);
36extern int dvb_usb_dvb_exit(struct dvb_usb_device *);
37
38extern int dvb_usb_fe_init(struct dvb_usb_device *);
39extern int dvb_usb_fe_exit(struct dvb_usb_device *);
40
41extern int dvb_usb_remote_init(struct dvb_usb_device *);
42extern int dvb_usb_remote_exit(struct dvb_usb_device *);
43
44#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
new file mode 100644
index 000000000000..bdd72f779707
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
@@ -0,0 +1,210 @@
1/* dvb-usb-dvb.c is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
5 *
6 * This file contains functions for initializing and handling the
7 * linux-dvb API.
8 */
9#include "dvb-usb-common.h"
10
11static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
12{
13 struct dvb_usb_device *d = dvbdmxfeed->demux->priv;
14 int newfeedcount,ret;
15
16 if (d == NULL)
17 return -ENODEV;
18
19 newfeedcount = d->feedcount + (onoff ? 1 : -1);
20
21 /*
22 * stop feed before setting a new pid if there will be no pid anymore
23 */
24 if (newfeedcount == 0) {
25 deb_ts("stop feeding\n");
26
27 if (d->props.streaming_ctrl != NULL)
28 if ((ret = d->props.streaming_ctrl(d,0)))
29 err("error while stopping stream.");
30
31 dvb_usb_urb_kill(d);
32 }
33
34 d->feedcount = newfeedcount;
35
36 /* activate the pid on the device specific pid_filter */
37 deb_ts("setting pid: %5d %04x at index %d '%s'\n",dvbdmxfeed->pid,dvbdmxfeed->pid,dvbdmxfeed->index,onoff ? "on" : "off");
38 if (d->props.caps & DVB_USB_HAS_PID_FILTER &&
39 d->pid_filtering &&
40 d->props.pid_filter != NULL)
41 d->props.pid_filter(d,dvbdmxfeed->index,dvbdmxfeed->pid,onoff);
42
43 /* start the feed if this was the first feed and there is still a feed
44 * for reception.
45 */
46 if (d->feedcount == onoff && d->feedcount > 0) {
47
48 deb_ts("controlling pid parser\n");
49 if (d->props.caps & DVB_USB_HAS_PID_FILTER &&
50 d->props.caps & DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF &&
51 d->props.pid_filter_ctrl != NULL)
52 if (d->props.pid_filter_ctrl(d,d->pid_filtering) < 0)
53 err("could not handle pid_parser");
54
55 deb_ts("start feeding\n");
56 if (d->props.streaming_ctrl != NULL)
57 if (d->props.streaming_ctrl(d,1)) {
58 err("error while enabling fifo.");
59 return -ENODEV;
60 }
61
62 dvb_usb_urb_submit(d);
63 }
64 return 0;
65}
66
67static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
68{
69 deb_ts("start pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid,dvbdmxfeed->type);
70 return dvb_usb_ctrl_feed(dvbdmxfeed,1);
71}
72
73static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
74{
75 deb_ts("stop pid: 0x%04x, feedtype: %d\n", dvbdmxfeed->pid, dvbdmxfeed->type);
76 return dvb_usb_ctrl_feed(dvbdmxfeed,0);
77}
78
79int dvb_usb_dvb_init(struct dvb_usb_device *d)
80{
81 int ret;
82
83 if ((ret = dvb_register_adapter(&d->dvb_adap, d->desc->name,
84 d->owner)) < 0) {
85 deb_info("dvb_register_adapter failed: error %d", ret);
86 goto err;
87 }
88 d->dvb_adap.priv = d;
89
90 if (d->props.read_mac_address) {
91 if (d->props.read_mac_address(d,d->dvb_adap.proposed_mac) == 0)
92 info("MAC address: %02x:%02x:%02x:%02x:%02x:%02x",d->dvb_adap.proposed_mac[0],
93 d->dvb_adap.proposed_mac[1],d->dvb_adap.proposed_mac[2],
94 d->dvb_adap.proposed_mac[3],d->dvb_adap.proposed_mac[4],
95 d->dvb_adap.proposed_mac[5]);
96 else
97 err("MAC address reading failed.");
98 }
99
100
101 d->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
102 d->demux.priv = d;
103
104 d->demux.feednum = d->demux.filternum = d->max_feed_count;
105 d->demux.start_feed = dvb_usb_start_feed;
106 d->demux.stop_feed = dvb_usb_stop_feed;
107 d->demux.write_to_decoder = NULL;
108 if ((ret = dvb_dmx_init(&d->demux)) < 0) {
109 err("dvb_dmx_init failed: error %d",ret);
110 goto err_dmx;
111 }
112
113 d->dmxdev.filternum = d->demux.filternum;
114 d->dmxdev.demux = &d->demux.dmx;
115 d->dmxdev.capabilities = 0;
116 if ((ret = dvb_dmxdev_init(&d->dmxdev, &d->dvb_adap)) < 0) {
117 err("dvb_dmxdev_init failed: error %d",ret);
118 goto err_dmx_dev;
119 }
120
121 dvb_net_init(&d->dvb_adap, &d->dvb_net, &d->demux.dmx);
122
123 goto success;
124err_dmx_dev:
125 dvb_dmx_release(&d->demux);
126err_dmx:
127 dvb_unregister_adapter(&d->dvb_adap);
128err:
129 return ret;
130success:
131 d->state |= DVB_USB_STATE_DVB;
132 return 0;
133}
134
135int dvb_usb_dvb_exit(struct dvb_usb_device *d)
136{
137 if (d->state & DVB_USB_STATE_DVB) {
138 deb_info("unregistering DVB part\n");
139 dvb_net_release(&d->dvb_net);
140 d->demux.dmx.close(&d->demux.dmx);
141 dvb_dmxdev_release(&d->dmxdev);
142 dvb_dmx_release(&d->demux);
143 dvb_unregister_adapter(&d->dvb_adap);
144 d->state &= ~DVB_USB_STATE_DVB;
145 }
146 return 0;
147}
148
149static int dvb_usb_fe_wakeup(struct dvb_frontend *fe)
150{
151 struct dvb_usb_device *d = fe->dvb->priv;
152
153 if (d->props.power_ctrl)
154 d->props.power_ctrl(d,1);
155
156 if (d->fe_init)
157 d->fe_init(fe);
158
159 return 0;
160}
161
162static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
163{
164 struct dvb_usb_device *d = fe->dvb->priv;
165
166 if (d->fe_sleep)
167 d->fe_sleep(fe);
168
169 if (d->props.power_ctrl)
170 d->props.power_ctrl(d,0);
171
172 return 0;
173}
174
175int dvb_usb_fe_init(struct dvb_usb_device* d)
176{
177 if (d->props.frontend_attach == NULL) {
178 err("strange '%s' don't want to attach a frontend.",d->desc->name);
179 return 0;
180 }
181
182 d->props.frontend_attach(d);
183
184 /* re-assign sleep and wakeup functions */
185 if (d->fe != NULL) {
186 d->fe_init = d->fe->ops->init; d->fe->ops->init = dvb_usb_fe_wakeup;
187 d->fe_sleep = d->fe->ops->sleep; d->fe->ops->sleep = dvb_usb_fe_sleep;
188
189 if (dvb_register_frontend(&d->dvb_adap, d->fe)) {
190 err("Frontend registration failed.");
191 if (d->fe->ops->release)
192 d->fe->ops->release(d->fe);
193 d->fe = NULL;
194 return -ENODEV;
195 }
196 } else
197 err("no frontend was attached by '%s'",d->desc->name);
198
199 if (d->props.tuner_attach != NULL)
200 d->props.tuner_attach(d);
201
202 return 0;
203}
204
205int dvb_usb_fe_exit(struct dvb_usb_device *d)
206{
207 if (d->fe != NULL)
208 dvb_unregister_frontend(d->fe);
209 return 0;
210}
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c b/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c
new file mode 100644
index 000000000000..5244e39770a0
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c
@@ -0,0 +1,100 @@
1/* dvb-usb-firmware.c is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
5 *
6 * This file contains functions for downloading the firmware to Cypress FX 1 and 2 based devices.
7 *
8 * FIXME: This part does actually not belong to dvb-usb, but to the usb-subsystem.
9 */
10#include "dvb-usb-common.h"
11
12#include <linux/firmware.h>
13#include <linux/usb.h>
14
15struct usb_cypress_controller {
16 int id;
17 const char *name; /* name of the usb controller */
18 u16 cpu_cs_register; /* needs to be restarted, when the firmware has been downloaded. */
19};
20
21static struct usb_cypress_controller cypress[] = {
22 { .id = CYPRESS_AN2135, .name = "Cypress AN2135", .cpu_cs_register = 0x7f92 },
23 { .id = CYPRESS_AN2235, .name = "Cypress AN2235", .cpu_cs_register = 0x7f92 },
24 { .id = CYPRESS_FX2, .name = "Cypress FX2", .cpu_cs_register = 0xe600 },
25};
26
27/*
28 * load a firmware packet to the device
29 */
30static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 len)
31{
32 return usb_control_msg(udev, usb_sndctrlpipe(udev,0),
33 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5*HZ);
34}
35
36int usb_cypress_load_firmware(struct usb_device *udev, const char *filename, int type)
37{
38 const struct firmware *fw = NULL;
39 u16 addr;
40 u8 *b,*p;
41 int ret = 0,i;
42
43 if ((ret = request_firmware(&fw, filename, &udev->dev)) != 0) {
44 err("did not find the firmware file. (%s) "
45 "Please see linux/Documentation/dvb/ for more details on firmware-problems.",
46 filename);
47 return ret;
48 }
49
50 info("downloading firmware from file '%s' to the '%s'",filename,cypress[type].name);
51
52 p = kmalloc(fw->size,GFP_KERNEL);
53 if (p != NULL) {
54 u8 reset;
55 /*
56 * you cannot use the fw->data as buffer for
57 * usb_control_msg, a new buffer has to be
58 * created
59 */
60 memcpy(p,fw->data,fw->size);
61
62 /* stop the CPU */
63 reset = 1;
64 if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
65 err("could not stop the USB controller CPU.");
66 for(i = 0; p[i+3] == 0 && i < fw->size; ) {
67 b = (u8 *) &p[i];
68 addr = cpu_to_le16( *((u16 *) &b[1]) );
69
70 deb_fw("writing to address 0x%04x (buffer: 0x%02x%02x)\n",addr,b[1],b[2]);
71
72 ret = usb_cypress_writemem(udev,addr,&b[4],b[0]);
73
74 if (ret != b[0]) {
75 err("error while transferring firmware "
76 "(transferred size: %d, block size: %d)",
77 ret,b[0]);
78 ret = -EINVAL;
79 break;
80 }
81 i += 5 + b[0];
82 }
83 /* length in ret */
84 if (ret > 0)
85 ret = 0;
86 /* restart the CPU */
87 reset = 0;
88 if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
89 err("could not restart the USB controller CPU.");
90 ret = -EINVAL;
91 }
92
93 kfree(p);
94 } else {
95 ret = -ENOMEM;
96 }
97 release_firmware(fw);
98
99 return ret;
100}
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
new file mode 100644
index 000000000000..9f0a8d90d146
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
@@ -0,0 +1,118 @@
1/* dvb-usb-i2c.c is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
5 *
6 * This file contains functions for (de-)initializing an I2C adapter.
7 */
8#include "dvb-usb-common.h"
9
10int dvb_usb_i2c_init(struct dvb_usb_device *d)
11{
12 int ret = 0;
13
14 if (!(d->props.caps & DVB_USB_IS_AN_I2C_ADAPTER))
15 return 0;
16
17 if (d->props.i2c_algo == NULL) {
18 err("no i2c algorithm specified");
19 return -EINVAL;
20 }
21
22 strncpy(d->i2c_adap.name,d->desc->name,I2C_NAME_SIZE);
23#ifdef I2C_ADAP_CLASS_TV_DIGITAL
24 d->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
25#else
26 d->i2c_adap.class = I2C_CLASS_TV_DIGITAL,
27#endif
28 d->i2c_adap.algo = d->props.i2c_algo;
29 d->i2c_adap.algo_data = NULL;
30 d->i2c_adap.id = I2C_ALGO_BIT;
31
32 i2c_set_adapdata(&d->i2c_adap, d);
33
34 if ((ret = i2c_add_adapter(&d->i2c_adap)) < 0)
35 err("could not add i2c adapter");
36
37 d->state |= DVB_USB_STATE_I2C;
38
39 return ret;
40}
41
42int dvb_usb_i2c_exit(struct dvb_usb_device *d)
43{
44 if (d->state & DVB_USB_STATE_I2C)
45 i2c_del_adapter(&d->i2c_adap);
46 d->state &= ~DVB_USB_STATE_I2C;
47 return 0;
48}
49
50int dvb_usb_pll_init_i2c(struct dvb_frontend *fe)
51{
52 struct dvb_usb_device *d = fe->dvb->priv;
53 struct i2c_msg msg = { .addr = d->pll_addr, .flags = 0, .buf = d->pll_init, .len = 4 };
54 int ret = 0;
55
56 /* if there is nothing to initialize */
57 if (d->pll_init[0] == 0x00 && d->pll_init[1] == 0x00 &&
58 d->pll_init[2] == 0x00 && d->pll_init[3] == 0x00)
59 return 0;
60
61 if (d->tuner_pass_ctrl)
62 d->tuner_pass_ctrl(fe,1,d->pll_addr);
63
64 deb_pll("pll init: %x\n",d->pll_addr);
65 deb_pll("pll-buf: %x %x %x %x\n",d->pll_init[0],d->pll_init[1],
66 d->pll_init[2],d->pll_init[3]);
67
68 if (i2c_transfer (&d->i2c_adap, &msg, 1) != 1) {
69 err("tuner i2c write failed for pll_init.");
70 ret = -EREMOTEIO;
71 }
72 msleep(1);
73
74 if (d->tuner_pass_ctrl)
75 d->tuner_pass_ctrl(fe,0,d->pll_addr);
76 return ret;
77}
78EXPORT_SYMBOL(dvb_usb_pll_init_i2c);
79
80int dvb_usb_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep, u8 b[5])
81{
82 struct dvb_usb_device *d = fe->dvb->priv;
83
84 deb_pll("pll addr: %x, freq: %d %p\n",d->pll_addr,fep->frequency,d->pll_desc);
85
86 b[0] = d->pll_addr << 1;
87 dvb_pll_configure(d->pll_desc,&b[1],fep->frequency,fep->u.ofdm.bandwidth);
88
89 deb_pll("pll-buf: %x %x %x %x %x\n",b[0],b[1],b[2],b[3],b[4]);
90
91 return 0;
92}
93EXPORT_SYMBOL(dvb_usb_pll_set);
94
95int dvb_usb_pll_set_i2c(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
96{
97 struct dvb_usb_device *d = fe->dvb->priv;
98 int ret = 0;
99 u8 b[5];
100 struct i2c_msg msg = { .addr = d->pll_addr, .flags = 0, .buf = &b[1], .len = 4 };
101
102 dvb_usb_pll_set(fe,fep,b);
103
104 if (d->tuner_pass_ctrl)
105 d->tuner_pass_ctrl(fe,1,d->pll_addr);
106
107 if (i2c_transfer (&d->i2c_adap, &msg, 1) != 1) {
108 err("tuner i2c write failed for pll_set.");
109 ret = -EREMOTEIO;
110 }
111 msleep(1);
112
113 if (d->tuner_pass_ctrl)
114 d->tuner_pass_ctrl(fe,0,d->pll_addr);
115
116 return ret;
117}
118EXPORT_SYMBOL(dvb_usb_pll_set_i2c);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
new file mode 100644
index 000000000000..bcb34191868b
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -0,0 +1,83 @@
1/* dvb-usb-ids.h is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) see
4 * dvb-usb-init.c for copyright information.
5 *
6 * a header file containing define's for the USB device supported by the
7 * various drivers.
8 */
9#ifndef _DVB_USB_IDS_H_
10#define _DVB_USB_IDS_H_
11
12/* Vendor IDs */
13#define USB_VID_ADSTECH 0x06e1
14#define USB_VID_ANCHOR 0x0547
15#define USB_VID_AVERMEDIA_UNK 0x14aa
16#define USB_VID_AVERMEDIA 0x07ca
17#define USB_VID_COMPRO 0x185b
18#define USB_VID_COMPRO_UNK 0x145f
19#define USB_VID_CYPRESS 0x04b4
20#define USB_VID_DIBCOM 0x10b8
21#define USB_VID_DVICO 0x0fe9
22#define USB_VID_EMPIA 0xeb1a
23#define USB_VID_GRANDTEC 0x5032
24#define USB_VID_HANFTEK 0x15f4
25#define USB_VID_HAUPPAUGE 0x2040
26#define USB_VID_HYPER_PALTEK 0x1025
27#define USB_VID_VISIONPLUS 0x13d3
28#define USB_VID_TWINHAN 0x1822
29#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
30
31/* Product IDs */
32#define USB_PID_ADSTECH_USB2_COLD 0xa333
33#define USB_PID_ADSTECH_USB2_WARM 0xa334
34#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001
35#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002
36#define USB_PID_AVERMEDIA_DVBT_USB2_COLD 0xa800
37#define USB_PID_AVERMEDIA_DVBT_USB2_WARM 0xa801
38#define USB_PID_COMPRO_DVBU2000_COLD 0xd000
39#define USB_PID_COMPRO_DVBU2000_WARM 0xd001
40#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c
41#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d
42#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
43#define USB_PID_DIBCOM_MOD3000_WARM 0x0bb9
44#define USB_PID_DIBCOM_MOD3001_COLD 0x0bc6
45#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7
46#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
47#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
48#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
49#define USB_PID_KWORLD_VSTREAM_COLD 0x17de
50#define USB_PID_KWORLD_VSTREAM_WARM 0x17df
51#define USB_PID_TWINHAN_VP7041_COLD 0x3201
52#define USB_PID_TWINHAN_VP7041_WARM 0x3202
53#define USB_PID_TWINHAN_VP7045_COLD 0x3205
54#define USB_PID_TWINHAN_VP7045_WARM 0x3206
55#define USB_PID_DNTV_TINYUSB2_COLD 0x3223
56#define USB_PID_DNTV_TINYUSB2_WARM 0x3224
57#define USB_PID_TWINHAN_VP7021_COLD 0x3207
58#define USB_PID_TWINHAN_VP7021_WARM 0x3208
59#define USB_PID_ULTIMA_TVBOX_COLD 0x8105
60#define USB_PID_ULTIMA_TVBOX_WARM 0x8106
61#define USB_PID_ULTIMA_TVBOX_AN2235_COLD 0x8107
62#define USB_PID_ULTIMA_TVBOX_AN2235_WARM 0x8108
63#define USB_PID_ULTIMA_TVBOX_ANCHOR_COLD 0x2235
64#define USB_PID_ULTIMA_TVBOX_USB2_COLD 0x8109
65#define USB_PID_ULTIMA_TVBOX_USB2_FX_COLD 0x8613
66#define USB_PID_ULTIMA_TVBOX_USB2_FX_WARM 0x1002
67#define USB_PID_UNK_HYPER_PALTEK_COLD 0x005e
68#define USB_PID_UNK_HYPER_PALTEK_WARM 0x005f
69#define USB_PID_HANFTEK_UMT_010_COLD 0x0001
70#define USB_PID_HANFTEK_UMT_010_WARM 0x0015
71#define USB_PID_DTT200U_COLD 0x0201
72#define USB_PID_DTT200U_WARM 0x0301
73#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300
74#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301
75#define USB_PID_NEBULA_DIGITV 0x0201
76#define USB_PID_DVICO_BLUEBIRD_LGZ201 0xdb00
77#define USB_PID_DVICO_BLUEBIRD_TH7579 0xdb10
78#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820
79#define USB_PID_DVICO_BLUEBIRD_LGZ201_1 0xdb01
80#define USB_PID_DVICO_BLUEBIRD_TH7579_2 0xdb11
81
82
83#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
new file mode 100644
index 000000000000..3aadec974cf1
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -0,0 +1,211 @@
1/*
2 * DVB USB library - provides a generic interface for a DVB USB device driver.
3 *
4 * dvb-usb-init.c
5 *
6 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
7 *
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.
11 *
12 * see Documentation/dvb/README.dvb-usb for more information
13 */
14#include "dvb-usb-common.h"
15
16/* debug */
17int dvb_usb_debug;
18module_param_named(debug,dvb_usb_debug, int, 0644);
19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))." DVB_USB_DEBUG_STATUS);
20
21/* general initialization functions */
22int dvb_usb_exit(struct dvb_usb_device *d)
23{
24 deb_info("state before exiting everything: %x\n",d->state);
25 dvb_usb_remote_exit(d);
26 dvb_usb_fe_exit(d);
27 dvb_usb_i2c_exit(d);
28 dvb_usb_dvb_exit(d);
29 dvb_usb_urb_exit(d);
30 deb_info("state should be zero now: %x\n",d->state);
31 d->state = DVB_USB_STATE_INIT;
32 kfree(d->priv);
33 kfree(d);
34 return 0;
35}
36
37static int dvb_usb_init(struct dvb_usb_device *d)
38{
39 int ret = 0;
40
41 sema_init(&d->usb_sem, 1);
42 sema_init(&d->i2c_sem, 1);
43
44 d->state = DVB_USB_STATE_INIT;
45
46/* check the capabilites and set appropriate variables */
47
48/* speed - when running at FULL speed we need a HW PID filter */
49 if (d->udev->speed == USB_SPEED_FULL && !(d->props.caps & DVB_USB_HAS_PID_FILTER)) {
50 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a HW PID filter)");
51 return -ENODEV;
52 }
53
54 if ((d->udev->speed == USB_SPEED_FULL && d->props.caps & DVB_USB_HAS_PID_FILTER) ||
55 (d->props.caps & DVB_USB_NEED_PID_FILTERING)) {
56 info("will use the device's hw PID filter.");
57 d->pid_filtering = 1;
58 d->max_feed_count = d->props.pid_filter_count;
59 } else {
60 info("will pass the complete MPEG2 transport stream to the demuxer.");
61 d->pid_filtering = 0;
62 d->max_feed_count = 255;
63 }
64
65 if (d->props.power_ctrl)
66 d->props.power_ctrl(d,1);
67
68 if ((ret = dvb_usb_urb_init(d)) ||
69 (ret = dvb_usb_dvb_init(d)) ||
70 (ret = dvb_usb_i2c_init(d)) ||
71 (ret = dvb_usb_fe_init(d))) {
72 dvb_usb_exit(d);
73 return ret;
74 }
75
76 if ((ret = dvb_usb_remote_init(d)))
77 err("could not initialize remote control.");
78
79 if (d->props.power_ctrl)
80 d->props.power_ctrl(d,0);
81
82 return 0;
83}
84
85/* determine the name and the state of the just found USB device */
86static struct dvb_usb_device_description * dvb_usb_find_device(struct usb_device *udev,struct dvb_usb_properties *props, int *cold)
87{
88 int i,j;
89 struct dvb_usb_device_description *desc = NULL;
90 *cold = -1;
91
92 for (i = 0; i < props->num_device_descs; i++) {
93
94 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].cold_ids[j] != NULL; j++) {
95 deb_info("check for cold %x %x\n",props->devices[i].cold_ids[j]->idVendor, props->devices[i].cold_ids[j]->idProduct);
96 if (props->devices[i].cold_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
97 props->devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
98 *cold = 1;
99 desc = &props->devices[i];
100 break;
101 }
102 }
103
104 if (desc != NULL)
105 break;
106
107 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].warm_ids[j] != NULL; j++) {
108 deb_info("check for warm %x %x\n",props->devices[i].warm_ids[j]->idVendor, props->devices[i].warm_ids[j]->idProduct);
109 if (props->devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
110 props->devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
111 *cold = 0;
112 desc = &props->devices[i];
113 break;
114 }
115 }
116 }
117
118 if (desc != NULL && props->identify_state != NULL)
119 props->identify_state(udev,props,&desc,cold);
120
121 return desc;
122}
123
124/*
125 * USB
126 */
127int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties *props, struct module *owner)
128{
129 struct usb_device *udev = interface_to_usbdev(intf);
130 struct dvb_usb_device *d = NULL;
131 struct dvb_usb_device_description *desc = NULL;
132
133 int ret = -ENOMEM,cold=0;
134
135 if ((desc = dvb_usb_find_device(udev,props,&cold)) == NULL) {
136 deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n");
137 return -ENODEV;
138 }
139
140 if (cold) {
141 info("found a '%s' in cold state, will try to load a firmware",desc->name);
142 ret = usb_cypress_load_firmware(udev,props->firmware,props->usb_ctrl);
143 } else {
144 info("found a '%s' in warm state.",desc->name);
145 d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
146 if (d == NULL) {
147 err("no memory for 'struct dvb_usb_device'");
148 return ret;
149 }
150 memset(d,0,sizeof(struct dvb_usb_device));
151
152 d->udev = udev;
153 memcpy(&d->props,props,sizeof(struct dvb_usb_properties));
154 d->desc = desc;
155 d->owner = owner;
156
157 if (d->props.size_of_priv > 0) {
158 d->priv = kmalloc(d->props.size_of_priv,GFP_KERNEL);
159 if (d->priv == NULL) {
160 err("no memory for priv in 'struct dvb_usb_device'");
161 kfree(d);
162 return -ENOMEM;
163 }
164 memset(d->priv,0,d->props.size_of_priv);
165 }
166
167 usb_set_intfdata(intf, d);
168
169 ret = dvb_usb_init(d);
170 }
171
172 if (ret == 0)
173 info("%s successfully initialized and connected.",desc->name);
174 else
175 info("%s error while loading driver (%d)",desc->name,ret);
176 return ret;
177}
178EXPORT_SYMBOL(dvb_usb_device_init);
179
180void dvb_usb_device_exit(struct usb_interface *intf)
181{
182 struct dvb_usb_device *d = usb_get_intfdata(intf);
183 const char *name = "generic DVB-USB module";
184
185 usb_set_intfdata(intf,NULL);
186 if (d != NULL && d->desc != NULL) {
187 name = d->desc->name;
188 dvb_usb_exit(d);
189 }
190 info("%s successfully deinitialized and disconnected.",name);
191
192}
193EXPORT_SYMBOL(dvb_usb_device_exit);
194
195/* module stuff */
196static int __init dvb_usb_module_init(void)
197{
198 return 0;
199}
200
201static void __exit dvb_usb_module_exit(void)
202{
203}
204
205module_init (dvb_usb_module_init);
206module_exit (dvb_usb_module_exit);
207
208MODULE_VERSION("0.3");
209MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
210MODULE_DESCRIPTION("A library module containing commonly used USB and DVB function USB DVB devices");
211MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
new file mode 100644
index 000000000000..9f1e23f82bae
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -0,0 +1,175 @@
1/* dvb-usb-remote.c is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
5 *
6 * This file contains functions for initializing the the input-device and for handling remote-control-queries.
7 */
8#include "dvb-usb-common.h"
9
10/* Remote-control poll function - called every dib->rc_query_interval ms to see
11 * whether the remote control has received anything.
12 *
13 * TODO: Fix the repeat rate of the input device.
14 */
15static void dvb_usb_read_remote_control(void *data)
16{
17 struct dvb_usb_device *d = data;
18 u32 event;
19 int state;
20
21 /* TODO: need a lock here. We can simply skip checking for the remote control
22 if we're busy. */
23
24 if (d->props.rc_query(d,&event,&state)) {
25 err("error while querying for an remote control event.");
26 goto schedule;
27 }
28
29
30 switch (state) {
31 case REMOTE_NO_KEY_PRESSED:
32 break;
33 case REMOTE_KEY_PRESSED:
34 deb_rc("key pressed\n");
35 d->last_event = event;
36 case REMOTE_KEY_REPEAT:
37 deb_rc("key repeated\n");
38 input_event(&d->rc_input_dev, EV_KEY, event, 1);
39 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0);
40 input_sync(&d->rc_input_dev);
41 break;
42 default:
43 break;
44 }
45
46/* improved repeat handling ???
47 switch (state) {
48 case REMOTE_NO_KEY_PRESSED:
49 deb_rc("NO KEY PRESSED\n");
50 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
51 deb_rc("releasing event %d\n",d->last_event);
52 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0);
53 input_sync(&d->rc_input_dev);
54 }
55 d->last_state = REMOTE_NO_KEY_PRESSED;
56 d->last_event = 0;
57 break;
58 case REMOTE_KEY_PRESSED:
59 deb_rc("KEY PRESSED\n");
60 deb_rc("pressing event %d\n",event);
61
62 input_event(&d->rc_input_dev, EV_KEY, event, 1);
63 input_sync(&d->rc_input_dev);
64
65 d->last_event = event;
66 d->last_state = REMOTE_KEY_PRESSED;
67 break;
68 case REMOTE_KEY_REPEAT:
69 deb_rc("KEY_REPEAT\n");
70 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
71 deb_rc("repeating event %d\n",d->last_event);
72 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 2);
73 input_sync(&d->rc_input_dev);
74 d->last_state = REMOTE_KEY_REPEAT;
75 }
76 default:
77 break;
78 }
79*/
80
81schedule:
82 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval));
83}
84
85int dvb_usb_remote_init(struct dvb_usb_device *d)
86{
87 int i;
88 if (d->props.rc_key_map == NULL)
89 return 0;
90
91 /* Initialise the remote-control structures.*/
92 init_input_dev(&d->rc_input_dev);
93
94 d->rc_input_dev.evbit[0] = BIT(EV_KEY);
95 d->rc_input_dev.keycodesize = sizeof(unsigned char);
96 d->rc_input_dev.keycodemax = KEY_MAX;
97 d->rc_input_dev.name = "IR-receiver inside an USB DVB receiver";
98
99 /* set the bits for the keys */
100 deb_rc("key map size: %d\n",d->props.rc_key_map_size);
101 for (i = 0; i < d->props.rc_key_map_size; i++) {
102 deb_rc("setting bit for event %d item %d\n",d->props.rc_key_map[i].event, i);
103 set_bit(d->props.rc_key_map[i].event, d->rc_input_dev.keybit);
104 }
105
106 /* Start the remote-control polling. */
107 if (d->props.rc_interval < 40)
108 d->props.rc_interval = 100; /* default */
109
110 /* setting these two values to non-zero, we have to manage key repeats */
111 d->rc_input_dev.rep[REP_PERIOD] = d->props.rc_interval;
112 d->rc_input_dev.rep[REP_DELAY] = d->props.rc_interval + 150;
113
114 input_register_device(&d->rc_input_dev);
115
116 INIT_WORK(&d->rc_query_work, dvb_usb_read_remote_control, d);
117
118 info("schedule remote query interval to %d msecs.",d->props.rc_interval);
119 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval));
120
121 d->state |= DVB_USB_STATE_REMOTE;
122
123 return 0;
124}
125
126int dvb_usb_remote_exit(struct dvb_usb_device *d)
127{
128 if (d->state & DVB_USB_STATE_REMOTE) {
129 cancel_delayed_work(&d->rc_query_work);
130 flush_scheduled_work();
131 input_unregister_device(&d->rc_input_dev);
132 }
133 d->state &= ~DVB_USB_STATE_REMOTE;
134 return 0;
135}
136
137#define DVB_USB_RC_NEC_EMPTY 0x00
138#define DVB_USB_RC_NEC_KEY_PRESSED 0x01
139#define DVB_USB_RC_NEC_KEY_REPEATED 0x02
140int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
141 u8 keybuf[5], u32 *event, int *state)
142{
143 int i;
144 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
145 *event = 0;
146 *state = REMOTE_NO_KEY_PRESSED;
147 switch (keybuf[0]) {
148 case DVB_USB_RC_NEC_EMPTY:
149 break;
150 case DVB_USB_RC_NEC_KEY_PRESSED:
151 if ((u8) ~keybuf[1] != keybuf[2] ||
152 (u8) ~keybuf[3] != keybuf[4]) {
153 deb_err("remote control checksum failed.\n");
154 break;
155 }
156 /* See if we can match the raw key code. */
157 for (i = 0; i < sizeof(keymap)/sizeof(struct dvb_usb_rc_key); i++)
158 if (keymap[i].custom == keybuf[1] &&
159 keymap[i].data == keybuf[3]) {
160 *event = keymap[i].event;
161 *state = REMOTE_KEY_PRESSED;
162 break;
163 }
164 deb_err("key mapping failed - no appropriate key found in keymapping\n");
165 break;
166 case DVB_USB_RC_NEC_KEY_REPEATED:
167 *state = REMOTE_KEY_REPEAT;
168 break;
169 default:
170 deb_err("unkown type of remote status: %d\n",keybuf[0]);
171 break;
172 }
173 return 0;
174}
175EXPORT_SYMBOL(dvb_usb_nec_rc_key_to_event);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
new file mode 100644
index 000000000000..83d476fb410a
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
@@ -0,0 +1,211 @@
1/* dvb-usb-urb.c is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
5 *
6 * This file contains functions for initializing and handling the
7 * USB and URB stuff.
8 */
9#include "dvb-usb-common.h"
10
11int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
12 u16 rlen, int delay_ms)
13{
14 int actlen,ret = -ENOMEM;
15
16 if (d->props.generic_bulk_ctrl_endpoint == 0) {
17 err("endpoint for generic control not specified.");
18 return -EINVAL;
19 }
20
21 if (wbuf == NULL || wlen == 0)
22 return -EINVAL;
23
24 if ((ret = down_interruptible(&d->usb_sem)))
25 return ret;
26
27 debug_dump(wbuf,wlen,deb_xfer);
28
29 ret = usb_bulk_msg(d->udev,usb_sndbulkpipe(d->udev,
30 d->props.generic_bulk_ctrl_endpoint), wbuf,wlen,&actlen,
31 2*HZ);
32
33 if (ret)
34 err("bulk message failed: %d (%d/%d)",ret,wlen,actlen);
35 else
36 ret = actlen != wlen ? -1 : 0;
37
38 /* an answer is expected, and no error before */
39 if (!ret && rbuf && rlen) {
40 if (delay_ms)
41 msleep(delay_ms);
42
43 ret = usb_bulk_msg(d->udev,usb_rcvbulkpipe(d->udev,
44 d->props.generic_bulk_ctrl_endpoint),rbuf,rlen,&actlen,
45 2*HZ);
46
47 if (ret)
48 err("recv bulk message failed: %d",ret);
49 else
50 debug_dump(rbuf,actlen,deb_xfer);
51 }
52
53 up(&d->usb_sem);
54 return ret;
55}
56EXPORT_SYMBOL(dvb_usb_generic_rw);
57
58int dvb_usb_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
59{
60 return dvb_usb_generic_rw(d,buf,len,NULL,0,0);
61}
62EXPORT_SYMBOL(dvb_usb_generic_write);
63
64static void dvb_usb_bulk_urb_complete(struct urb *urb, struct pt_regs *ptregs)
65{
66 struct dvb_usb_device *d = urb->context;
67
68 deb_ts("bulk urb completed. feedcount: %d, status: %d, length: %d\n",d->feedcount,urb->status,
69 urb->actual_length);
70
71 switch (urb->status) {
72 case 0: /* success */
73 case -ETIMEDOUT: /* NAK */
74 break;
75 case -ECONNRESET: /* kill */
76 case -ENOENT:
77 case -ESHUTDOWN:
78 return;
79 default: /* error */
80 deb_ts("urb completition error %d.", urb->status);
81 break;
82 }
83
84 if (d->feedcount > 0 && urb->actual_length > 0) {
85 if (d->state & DVB_USB_STATE_DVB)
86 dvb_dmx_swfilter(&d->demux, (u8*) urb->transfer_buffer,urb->actual_length);
87 } else
88 deb_ts("URB dropped because of feedcount.\n");
89
90 usb_submit_urb(urb,GFP_ATOMIC);
91}
92
93int dvb_usb_urb_kill(struct dvb_usb_device *d)
94{
95 int i;
96 for (i = 0; i < d->urbs_submitted; i++) {
97 deb_info("killing URB no. %d.\n",i);
98
99 /* stop the URB */
100 usb_kill_urb(d->urb_list[i]);
101 }
102 d->urbs_submitted = 0;
103 return 0;
104}
105
106int dvb_usb_urb_submit(struct dvb_usb_device *d)
107{
108 int i,ret;
109 for (i = 0; i < d->urbs_initialized; i++) {
110 deb_info("submitting URB no. %d\n",i);
111 if ((ret = usb_submit_urb(d->urb_list[i],GFP_ATOMIC))) {
112 err("could not submit URB no. %d - get them all back\n",i);
113 dvb_usb_urb_kill(d);
114 return ret;
115 }
116 d->urbs_submitted++;
117 }
118 return 0;
119}
120
121static int dvb_usb_bulk_urb_init(struct dvb_usb_device *d)
122{
123 int i,bufsize = d->props.urb.count * d->props.urb.u.bulk.buffersize;
124
125 deb_info("allocate %d bytes as buffersize for all URBs\n",bufsize);
126 /* allocate the actual buffer for the URBs */
127 if ((d->buffer = usb_buffer_alloc(d->udev, bufsize, SLAB_ATOMIC, &d->dma_handle)) == NULL) {
128 deb_info("not enough memory for urb-buffer allocation.\n");
129 return -ENOMEM;
130 }
131 deb_info("allocation successful\n");
132 memset(d->buffer,0,bufsize);
133
134 d->state |= DVB_USB_STATE_URB_BUF;
135
136 /* allocate the URBs */
137 for (i = 0; i < d->props.urb.count; i++) {
138 if (!(d->urb_list[i] = usb_alloc_urb(0,GFP_ATOMIC))) {
139 return -ENOMEM;
140 }
141
142 usb_fill_bulk_urb( d->urb_list[i], d->udev,
143 usb_rcvbulkpipe(d->udev,d->props.urb.endpoint),
144 &d->buffer[i*d->props.urb.u.bulk.buffersize],
145 d->props.urb.u.bulk.buffersize,
146 dvb_usb_bulk_urb_complete, d);
147
148 d->urb_list[i]->transfer_flags = 0;
149 d->urbs_initialized++;
150 }
151 return 0;
152}
153
154int dvb_usb_urb_init(struct dvb_usb_device *d)
155{
156 /*
157 * when reloading the driver w/o replugging the device
158 * sometimes a timeout occures, this helps
159 */
160 if (d->props.generic_bulk_ctrl_endpoint != 0) {
161 usb_clear_halt(d->udev,usb_sndbulkpipe(d->udev,d->props.generic_bulk_ctrl_endpoint));
162 usb_clear_halt(d->udev,usb_rcvbulkpipe(d->udev,d->props.generic_bulk_ctrl_endpoint));
163 }
164 usb_clear_halt(d->udev,usb_rcvbulkpipe(d->udev,d->props.urb.endpoint));
165
166 /* allocate the array for the data transfer URBs */
167 d->urb_list = kmalloc(d->props.urb.count * sizeof(struct urb *),GFP_KERNEL);
168 if (d->urb_list == NULL)
169 return -ENOMEM;
170 memset(d->urb_list,0,d->props.urb.count * sizeof(struct urb *));
171 d->state |= DVB_USB_STATE_URB_LIST;
172
173 switch (d->props.urb.type) {
174 case DVB_USB_BULK:
175 return dvb_usb_bulk_urb_init(d);
176 case DVB_USB_ISOC:
177 err("isochronous transfer not yet implemented in dvb-usb.");
178 return -EINVAL;
179 default:
180 err("unkown URB-type for data transfer.");
181 return -EINVAL;
182 }
183}
184
185int dvb_usb_urb_exit(struct dvb_usb_device *d)
186{
187 int i;
188
189 dvb_usb_urb_kill(d);
190
191 if (d->state & DVB_USB_STATE_URB_LIST) {
192 for (i = 0; i < d->urbs_initialized; i++) {
193 if (d->urb_list[i] != NULL) {
194 deb_info("freeing URB no. %d.\n",i);
195 /* free the URBs */
196 usb_free_urb(d->urb_list[i]);
197 }
198 }
199 d->urbs_initialized = 0;
200 /* free the urb array */
201 kfree(d->urb_list);
202 d->state &= ~DVB_USB_STATE_URB_LIST;
203 }
204
205 if (d->state & DVB_USB_STATE_URB_BUF)
206 usb_buffer_free(d->udev, d->props.urb.u.bulk.buffersize * d->props.urb.count,
207 d->buffer, d->dma_handle);
208
209 d->state &= ~DVB_USB_STATE_URB_BUF;
210 return 0;
211}
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
new file mode 100644
index 000000000000..abcee1943f64
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -0,0 +1,315 @@
1/* dvb-usb.h is part of the DVB USB library.
2 *
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
5 *
6 * the headerfile, all dvb-usb-drivers have to include.
7 */
8#ifndef __DVB_USB_H__
9#define __DVB_USB_H__
10
11#include <linux/config.h>
12#include <linux/input.h>
13#include <linux/module.h>
14#include <linux/usb.h>
15
16#include "dvb_frontend.h"
17#include "dvb_demux.h"
18#include "dvb_net.h"
19#include "dmxdev.h"
20
21#include "dvb-pll.h"
22
23#include "dvb-usb-ids.h"
24
25/* debug */
26#ifdef CONFIG_DVB_USB_DEBUG
27#define dprintk(var,level,args...) \
28 do { if ((var & level)) { printk(args); } } while (0)
29
30#define debug_dump(b,l,func) {\
31 int loop_; \
32 for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
33 func("\n");\
34}
35#define DVB_USB_DEBUG_STATUS
36#else
37#define dprintk(args...)
38#define debug_dump(b,l,func)
39
40#define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
41
42#endif
43
44/* generic log methods - taken from usb.h */
45#ifndef DVB_USB_LOG_PREFIX
46 #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
47#endif
48
49#undef err
50#define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
51#undef info
52#define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
53#undef warn
54#define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
55
56/**
57 * struct dvb_usb_device_description - name and its according USB IDs
58 * @name: real name of the box, regardless which DVB USB device class is in use
59 * @cold_ids: array of struct usb_device_id which describe the device in
60 * pre-firmware state
61 * @warm_ids: array of struct usb_device_id which describe the device in
62 * post-firmware state
63 *
64 * Each DVB USB device class can have one or more actual devices, this struct
65 * assigns a name to it.
66 */
67struct dvb_usb_device_description {
68 const char *name;
69
70#define DVB_USB_ID_MAX_NUM 15
71 struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
72 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
73};
74
75/**
76 * struct dvb_usb_rc_key - a remote control key and its input-event
77 * @custom: the vendor/custom part of the key
78 * @data: the actual key part
79 * @event: the input event assigned to key identified by custom and data
80 */
81struct dvb_usb_rc_key {
82 u8 custom,data;
83 u32 event;
84};
85
86struct dvb_usb_device;
87
88/**
89 * struct dvb_usb_properties - properties of a dvb-usb-device
90 * @caps: capabilites of the DVB USB device.
91 * @pid_filter_count: number of PID filter position in the optional hardware
92 * PID-filter.
93 *
94 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
95 * download.
96 * @firmware: name of the firmware file.
97 *
98 * @size_of_priv: how many bytes shall be allocated for the private field
99 * of struct dvb_usb_device.
100 *
101 * @power_ctrl: called to enable/disable power of the device.
102 * @streaming_crtl: called to start and stop the MPEG2-TS streaming of the
103 * device (not URB submitting/killing).
104 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
105 * @pid_filter: called to set/unset a PID for filtering.
106 *
107 * @read_mac_address: called to read the MAC address of the device.
108 *
109 * @frontend_attach: called to attach the possible frontends (fill fe-field
110 * of struct dvb_usb_device).
111 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
112 * pll_desc and pll_init_buf of struct dvb_usb_device).
113 * @identify_state: called to determine the state (cold or warm), when it
114 * is not distinguishable by the USB IDs.
115 *
116 * @rc_key_map: a hard-wired array of struct dvb_usb_rc_key (NULL to disable
117 * remote control handling).
118 * @rc_key_map_size: number of items in @rc_key_map.
119 * @rc_query: called to query an event event.
120 * @rc_interval: time in ms between two queries.
121 *
122 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
123 *
124 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
125 * endpoint which received control messages with bulk transfers. When this
126 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
127 * helper functions.
128 *
129 * @urb: describes the kind of USB transfer used for MPEG2-TS-streaming.
130 * Currently only BULK is implemented
131 *
132 * @num_device_descs: number of struct dvb_usb_device_description in @devices
133 * @devices: array of struct dvb_usb_device_description compatibles with these
134 * properties.
135 */
136struct dvb_usb_properties {
137
138#define DVB_USB_HAS_PID_FILTER 0x01
139#define DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF 0x02
140#define DVB_USB_NEED_PID_FILTERING 0x04
141#define DVB_USB_IS_AN_I2C_ADAPTER 0x08
142 int caps;
143 int pid_filter_count;
144
145#define CYPRESS_AN2135 0
146#define CYPRESS_AN2235 1
147#define CYPRESS_FX2 2
148 int usb_ctrl;
149 const char *firmware;
150
151 int size_of_priv;
152
153 int (*power_ctrl) (struct dvb_usb_device *, int);
154 int (*streaming_ctrl) (struct dvb_usb_device *, int);
155 int (*pid_filter_ctrl) (struct dvb_usb_device *, int);
156 int (*pid_filter) (struct dvb_usb_device *, int, u16, int);
157
158 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
159 int (*frontend_attach) (struct dvb_usb_device *);
160 int (*tuner_attach) (struct dvb_usb_device *);
161
162 int (*identify_state) (struct usb_device *, struct dvb_usb_properties *,
163 struct dvb_usb_device_description **, int *);
164
165/* remote control properties */
166#define REMOTE_NO_KEY_PRESSED 0x00
167#define REMOTE_KEY_PRESSED 0x01
168#define REMOTE_KEY_REPEAT 0x02
169 struct dvb_usb_rc_key *rc_key_map;
170 int rc_key_map_size;
171 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
172 int rc_interval;
173
174 struct i2c_algorithm *i2c_algo;
175
176 int generic_bulk_ctrl_endpoint;
177
178 struct {
179#define DVB_USB_BULK 1
180#define DVB_USB_ISOC 2
181 int type;
182 int count;
183 int endpoint;
184
185 union {
186 struct {
187 int buffersize; /* per URB */
188 } bulk;
189 struct {
190 int framesperurb;
191 int framesize;
192 } isoc;
193 } u;
194 } urb;
195
196 int num_device_descs;
197 struct dvb_usb_device_description devices[8];
198};
199
200
201/**
202 * struct dvb_usb_device - object of a DVB USB device
203 * @props: copy of the struct dvb_usb_properties this device belongs to.
204 * @desc: pointer to the device's struct dvb_usb_device_description.
205 * @state: initialization and runtime state of the device.
206 *
207 * @udev: pointer to the device's struct usb_device.
208 * @urb_list: array of dynamically allocated struct urb for the MPEG2-TS-
209 * streaming.
210 * @buffer: buffer used to streaming.
211 * @dma_handle: dma_addr_t for buffer.
212 * @urbs_initialized: number of URBs initialized.
213 * @urbs_submitted: number of URBs submitted.
214 * @feedcount: number of reqested feeds (used for streaming-activation)
215 * @pid_filtering: is hardware pid_filtering used or not.
216 * @usb_sem: semaphore of USB control messages (reading needs two messages)
217 * @i2c_sem: semaphore for i2c-transfers
218 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
219 * @pll_addr: I2C address of the tuner for programming
220 * @pll_init: array containing the initialization buffer
221 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
222 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod
223 * @dvb_adap: device's dvb_adapter.
224 * @dmxdev: device's dmxdev.
225 * @demux: device's software demuxer.
226 * @dvb_net: device's dvb_net interfaces.
227 * @dvb_frontend: device's frontend.
228 * @max_feed_count: how many feeds can be handled simultaneously by this
229 * device
230 * @fe_sleep: rerouted frontend-sleep function.
231 * @fe_init: rerouted frontend-init (wakeup) function.
232 * @rc_input_dev: input device for the remote control.
233 * @rc_query_work: struct work_struct frequent rc queries
234 * @last_event: last triggered event
235 * @last_state: last state (no, pressed, repeat)
236 * @owner: owner of the dvb_adapter
237 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
238 * in size_of_priv of dvb_usb_properties).
239 */
240struct dvb_usb_device {
241 struct dvb_usb_properties props;
242 struct dvb_usb_device_description *desc;
243
244#define DVB_USB_STATE_INIT 0x000
245#define DVB_USB_STATE_URB_LIST 0x001
246#define DVB_USB_STATE_URB_BUF 0x002
247#define DVB_USB_STATE_DVB 0x004
248#define DVB_USB_STATE_I2C 0x008
249#define DVB_USB_STATE_REMOTE 0x010
250#define DVB_USB_STATE_URB_SUBMIT 0x020
251 int state;
252
253 /* usb */
254 struct usb_device *udev;
255 struct urb **urb_list;
256 u8 *buffer;
257 dma_addr_t dma_handle;
258 int urbs_initialized;
259 int urbs_submitted;
260
261 int feedcount;
262 int pid_filtering;
263
264 /* locking */
265 struct semaphore usb_sem;
266
267 /* i2c */
268 struct semaphore i2c_sem;
269 struct i2c_adapter i2c_adap;
270
271 /* tuner programming information */
272 u8 pll_addr;
273 u8 pll_init[4];
274 struct dvb_pll_desc *pll_desc;
275 int (*tuner_pass_ctrl)(struct dvb_frontend *, int, u8);
276
277 /* dvb */
278 struct dvb_adapter dvb_adap;
279 struct dmxdev dmxdev;
280 struct dvb_demux demux;
281 struct dvb_net dvb_net;
282 struct dvb_frontend* fe;
283 int max_feed_count;
284
285 int (*fe_sleep) (struct dvb_frontend *);
286 int (*fe_init) (struct dvb_frontend *);
287
288 /* remote control */
289 struct input_dev rc_input_dev;
290 struct work_struct rc_query_work;
291 u32 last_event;
292 int last_state;
293
294 struct module *owner;
295
296 void *priv;
297};
298
299extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_properties *, struct module *);
300extern void dvb_usb_device_exit(struct usb_interface *);
301
302/* the generic read/write method for device control */
303extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);
304extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
305
306/* commonly used remote control parsing */
307extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
308
309/* commonly used pll init and set functions */
310extern int dvb_usb_pll_init_i2c(struct dvb_frontend *);
311extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]);
312extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
313
314
315#endif
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
new file mode 100644
index 000000000000..9d83781aef95
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -0,0 +1,236 @@
1/* DVB USB framework compliant Linux driver for the Hauppauge WinTV-NOVA-T usb2
2 * DVB-T receiver.
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
9 *
10 * see Documentation/dvb/README.dvb-usb for more information
11 */
12#include "dibusb.h"
13
14static int debug;
15module_param(debug, int, 0644);
16MODULE_PARM_DESC(debug, "set debugging level (1=rc,2=eeprom (|-able))." DVB_USB_DEBUG_STATUS);
17
18#define deb_rc(args...) dprintk(debug,0x01,args)
19#define deb_ee(args...) dprintk(debug,0x02,args)
20
21/* Hauppauge NOVA-T USB2 keys */
22static struct dvb_usb_rc_key haupp_rc_keys [] = {
23 { 0x1e, 0x00, KEY_0 },
24 { 0x1e, 0x01, KEY_1 },
25 { 0x1e, 0x02, KEY_2 },
26 { 0x1e, 0x03, KEY_3 },
27 { 0x1e, 0x04, KEY_4 },
28 { 0x1e, 0x05, KEY_5 },
29 { 0x1e, 0x06, KEY_6 },
30 { 0x1e, 0x07, KEY_7 },
31 { 0x1e, 0x08, KEY_8 },
32 { 0x1e, 0x09, KEY_9 },
33 { 0x1e, 0x0a, KEY_KPASTERISK },
34 { 0x1e, 0x0b, KEY_RED },
35 { 0x1e, 0x0c, KEY_RADIO },
36 { 0x1e, 0x0d, KEY_MENU },
37 { 0x1e, 0x0e, KEY_GRAVE }, /* # */
38 { 0x1e, 0x0f, KEY_MUTE },
39 { 0x1e, 0x10, KEY_VOLUMEUP },
40 { 0x1e, 0x11, KEY_VOLUMEDOWN },
41 { 0x1e, 0x12, KEY_CHANNEL },
42 { 0x1e, 0x14, KEY_UP },
43 { 0x1e, 0x15, KEY_DOWN },
44 { 0x1e, 0x16, KEY_LEFT },
45 { 0x1e, 0x17, KEY_RIGHT },
46 { 0x1e, 0x18, KEY_VIDEO },
47 { 0x1e, 0x19, KEY_AUDIO },
48 { 0x1e, 0x1a, KEY_MEDIA },
49 { 0x1e, 0x1b, KEY_EPG },
50 { 0x1e, 0x1c, KEY_TV },
51 { 0x1e, 0x1e, KEY_NEXT },
52 { 0x1e, 0x1f, KEY_BACK },
53 { 0x1e, 0x20, KEY_CHANNELUP },
54 { 0x1e, 0x21, KEY_CHANNELDOWN },
55 { 0x1e, 0x24, KEY_LAST }, /* Skip backwards */
56 { 0x1e, 0x25, KEY_OK },
57 { 0x1e, 0x29, KEY_BLUE},
58 { 0x1e, 0x2e, KEY_GREEN },
59 { 0x1e, 0x30, KEY_PAUSE },
60 { 0x1e, 0x32, KEY_REWIND },
61 { 0x1e, 0x34, KEY_FASTFORWARD },
62 { 0x1e, 0x35, KEY_PLAY },
63 { 0x1e, 0x36, KEY_STOP },
64 { 0x1e, 0x37, KEY_RECORD },
65 { 0x1e, 0x38, KEY_YELLOW },
66 { 0x1e, 0x3b, KEY_GOTO },
67 { 0x1e, 0x3d, KEY_POWER },
68};
69
70/* Firmware bug? sometimes, when a new key is pressed, the previous pressed key
71 * is delivered. No workaround yet, maybe a new firmware.
72 */
73static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
74{
75 u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom;
76 u16 raw;
77 int i;
78 struct dibusb_state *st = d->priv;
79
80 dvb_usb_generic_rw(d,cmd,2,key,5,0);
81
82 *state = REMOTE_NO_KEY_PRESSED;
83 switch (key[0]) {
84 case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
85 raw = ((key[1] << 8) | key[2]) >> 3;
86 toggle = !!(raw & 0x800);
87 data = raw & 0x3f;
88 custom = (raw >> 6) & 0x1f;
89
90 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
91
92 for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) {
93 deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
94 if (haupp_rc_keys[i].data == data &&
95 haupp_rc_keys[i].custom == custom) {
96 *event = haupp_rc_keys[i].event;
97 *state = REMOTE_KEY_PRESSED;
98 if (st->old_toggle == toggle) {
99 if (st->last_repeat_count++ < 2)
100 *state = REMOTE_NO_KEY_PRESSED;
101 } else {
102 st->last_repeat_count = 0;
103 st->old_toggle = toggle;
104 }
105 break;
106 }
107 }
108
109 break;
110 case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
111 default:
112 break;
113 }
114
115 return 0;
116}
117
118static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
119{
120 int i;
121 u8 b;
122
123 mac[0] = 0x00;
124 mac[1] = 0x0d;
125 mac[2] = 0xfe;
126
127 /* this is a complete guess, but works for my box */
128 for (i = 136; i < 139; i++) {
129 dibusb_read_eeprom_byte(d,i, &b);
130
131 mac[5 - (i - 136)] = b;
132
133/* deb_ee("%02x ",b);
134 if ((i+1) % 16 == 0)
135 deb_ee("\n");*/
136 }
137
138 return 0;
139}
140
141/* USB Driver stuff */
142static struct dvb_usb_properties nova_t_properties;
143
144static int nova_t_probe(struct usb_interface *intf,
145 const struct usb_device_id *id)
146{
147 return dvb_usb_device_init(intf,&nova_t_properties,THIS_MODULE);
148}
149
150/* do not change the order of the ID table */
151static struct usb_device_id nova_t_table [] = {
152/* 00 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_COLD) },
153/* 01 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_WARM) },
154 { } /* Terminating entry */
155};
156MODULE_DEVICE_TABLE (usb, nova_t_table);
157
158static struct dvb_usb_properties nova_t_properties = {
159 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
160 .pid_filter_count = 32,
161
162 .usb_ctrl = CYPRESS_FX2,
163 .firmware = "dvb-usb-nova-t-usb2-01.fw",
164
165 .size_of_priv = sizeof(struct dibusb_state),
166
167 .streaming_ctrl = dibusb2_0_streaming_ctrl,
168 .pid_filter = dibusb_pid_filter,
169 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
170 .power_ctrl = dibusb2_0_power_ctrl,
171 .frontend_attach = dibusb_dib3000mc_frontend_attach,
172 .tuner_attach = dibusb_dib3000mc_tuner_attach,
173 .read_mac_address = nova_t_read_mac_address,
174
175 .rc_interval = 100,
176 .rc_key_map = haupp_rc_keys,
177 .rc_key_map_size = ARRAY_SIZE(haupp_rc_keys),
178 .rc_query = nova_t_rc_query,
179
180 .i2c_algo = &dibusb_i2c_algo,
181
182 .generic_bulk_ctrl_endpoint = 0x01,
183 /* parameter for the MPEG2-data transfer */
184 .urb = {
185 .type = DVB_USB_BULK,
186 .count = 7,
187 .endpoint = 0x06,
188 .u = {
189 .bulk = {
190 .buffersize = 4096,
191 }
192 }
193 },
194
195 .num_device_descs = 1,
196 .devices = {
197 { "Hauppauge WinTV-NOVA-T usb2",
198 { &nova_t_table[0], NULL },
199 { &nova_t_table[1], NULL },
200 },
201 }
202};
203
204static struct usb_driver nova_t_driver = {
205 .owner = THIS_MODULE,
206 .name = "Hauppauge WinTV-NOVA-T usb2",
207 .probe = nova_t_probe,
208 .disconnect = dvb_usb_device_exit,
209 .id_table = nova_t_table,
210};
211
212/* module stuff */
213static int __init nova_t_module_init(void)
214{
215 int result;
216 if ((result = usb_register(&nova_t_driver))) {
217 err("usb_register failed. Error number %d",result);
218 return result;
219 }
220
221 return 0;
222}
223
224static void __exit nova_t_module_exit(void)
225{
226 /* deregister this driver from the USB subsystem */
227 usb_deregister(&nova_t_driver);
228}
229
230module_init (nova_t_module_init);
231module_exit (nova_t_module_exit);
232
233MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
234MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2");
235MODULE_VERSION("1.0");
236MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/umt-010.c b/drivers/media/dvb/dvb-usb/umt-010.c
new file mode 100644
index 000000000000..aa560422ce7c
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/umt-010.c
@@ -0,0 +1,162 @@
1/* DVB USB framework compliant Linux driver for the HanfTek UMT-010 USB2.0
2 * DVB-T receiver.
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
9 *
10 * see Documentation/dvb/README.dvb-usb for more information
11 */
12#include "dibusb.h"
13
14#include "mt352.h"
15
16static int umt_mt352_demod_init(struct dvb_frontend *fe)
17{
18 static u8 mt352_clock_config[] = { 0x89, 0xb8, 0x2d };
19 static u8 mt352_reset[] = { 0x50, 0x80 };
20 static u8 mt352_mclk_ratio[] = { 0x8b, 0x00 };
21 static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0x40 };
22 static u8 mt352_agc_cfg[] = { 0x67, 0x10, 0xa0 };
23
24 static u8 mt352_sec_agc_cfg1[] = { 0x6a, 0xff };
25 static u8 mt352_sec_agc_cfg2[] = { 0x6d, 0xff };
26 static u8 mt352_sec_agc_cfg3[] = { 0x70, 0x40 };
27 static u8 mt352_sec_agc_cfg4[] = { 0x7b, 0x03 };
28 static u8 mt352_sec_agc_cfg5[] = { 0x7d, 0x0f };
29
30 static u8 mt352_acq_ctl[] = { 0x53, 0x50 };
31 static u8 mt352_input_freq_1[] = { 0x56, 0x31, 0x06 };
32
33 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
34 udelay(2000);
35 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
36 mt352_write(fe, mt352_mclk_ratio, sizeof(mt352_mclk_ratio));
37
38 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
39 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
40
41 mt352_write(fe, mt352_sec_agc_cfg1, sizeof(mt352_sec_agc_cfg1));
42 mt352_write(fe, mt352_sec_agc_cfg2, sizeof(mt352_sec_agc_cfg2));
43 mt352_write(fe, mt352_sec_agc_cfg3, sizeof(mt352_sec_agc_cfg3));
44 mt352_write(fe, mt352_sec_agc_cfg4, sizeof(mt352_sec_agc_cfg4));
45 mt352_write(fe, mt352_sec_agc_cfg5, sizeof(mt352_sec_agc_cfg5));
46
47 mt352_write(fe, mt352_acq_ctl, sizeof(mt352_acq_ctl));
48 mt352_write(fe, mt352_input_freq_1, sizeof(mt352_input_freq_1));
49
50 return 0;
51}
52
53static int umt_mt352_frontend_attach(struct dvb_usb_device *d)
54{
55 struct mt352_config umt_config;
56
57 memset(&umt_config,0,sizeof(struct mt352_config));
58 umt_config.demod_init = umt_mt352_demod_init;
59 umt_config.demod_address = 0xf;
60 umt_config.pll_set = dvb_usb_pll_set;
61
62 d->fe = mt352_attach(&umt_config, &d->i2c_adap);
63
64 return 0;
65}
66
67static int umt_tuner_attach (struct dvb_usb_device *d)
68{
69 d->pll_addr = 0x61;
70 d->pll_desc = &dvb_pll_tua6034;
71 return 0;
72}
73
74/* USB Driver stuff */
75static struct dvb_usb_properties umt_properties;
76
77static int umt_probe(struct usb_interface *intf,
78 const struct usb_device_id *id)
79{
80 if (dvb_usb_device_init(intf,&umt_properties,THIS_MODULE) == 0)
81 return 0;
82 return -EINVAL;
83}
84
85/* do not change the order of the ID table */
86static struct usb_device_id umt_table [] = {
87/* 00 */ { USB_DEVICE(USB_VID_HANFTEK, USB_PID_HANFTEK_UMT_010_COLD) },
88/* 01 */ { USB_DEVICE(USB_VID_HANFTEK, USB_PID_HANFTEK_UMT_010_WARM) },
89 { } /* Terminating entry */
90};
91MODULE_DEVICE_TABLE (usb, umt_table);
92
93static struct dvb_usb_properties umt_properties = {
94 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
95
96 .usb_ctrl = CYPRESS_FX2,
97 .firmware = "dvb-usb-umt-010-02.fw",
98
99 .size_of_priv = sizeof(struct dibusb_state),
100
101 .streaming_ctrl = dibusb2_0_streaming_ctrl,
102 .power_ctrl = dibusb_power_ctrl,
103 .frontend_attach = umt_mt352_frontend_attach,
104 .tuner_attach = umt_tuner_attach,
105
106 .i2c_algo = &dibusb_i2c_algo,
107
108 .generic_bulk_ctrl_endpoint = 0x01,
109 /* parameter for the MPEG2-data transfer */
110 .urb = {
111 .type = DVB_USB_BULK,
112 .count = 20,
113 .endpoint = 0x06,
114 .u = {
115 .bulk = {
116 .buffersize = 512,
117 }
118 }
119 },
120
121 .num_device_descs = 1,
122 .devices = {
123 { "Hanftek UMT-010 DVB-T USB2.0",
124 { &umt_table[0], NULL },
125 { &umt_table[1], NULL },
126 },
127 }
128};
129
130static struct usb_driver umt_driver = {
131 .owner = THIS_MODULE,
132 .name = "HanfTek UMT-010 USB2.0 DVB-T devices",
133 .probe = umt_probe,
134 .disconnect = dvb_usb_device_exit,
135 .id_table = umt_table,
136};
137
138/* module stuff */
139static int __init umt_module_init(void)
140{
141 int result;
142 if ((result = usb_register(&umt_driver))) {
143 err("usb_register failed. Error number %d",result);
144 return result;
145 }
146
147 return 0;
148}
149
150static void __exit umt_module_exit(void)
151{
152 /* deregister this driver from the USB subsystem */
153 usb_deregister(&umt_driver);
154}
155
156module_init (umt_module_init);
157module_exit (umt_module_exit);
158
159MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
160MODULE_DESCRIPTION("Driver for HanfTek UMT 010 USB2.0 DVB-T device");
161MODULE_VERSION("1.0");
162MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/vp7045-fe.c b/drivers/media/dvb/dvb-usb/vp7045-fe.c
new file mode 100644
index 000000000000..2746edfeccba
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/vp7045-fe.c
@@ -0,0 +1,196 @@
1/* DVB frontend part of the Linux driver for TwinhanDTV Alpha/MagicBoxII USB2.0
2 * DVB-T receiver.
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * Thanks to Twinhan who kindly provided hardware and information.
7 *
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.
11 *
12 * see Documentation/dvb/README.dvb-usb for more information
13 *
14 */
15#include "vp7045.h"
16
17/* It is a Zarlink MT352 within a Samsung Tuner (DNOS404ZH102A) - 040929 - AAT
18 *
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.
22 */
23
24struct vp7045_fe_state {
25 struct dvb_frontend fe;
26 struct dvb_usb_device *d;
27};
28
29
30static int vp7045_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
31{
32 struct vp7045_fe_state *state = fe->demodulator_priv;
33 u8 s0 = vp7045_read_reg(state->d,0x00),
34 s1 = vp7045_read_reg(state->d,0x01),
35 s3 = vp7045_read_reg(state->d,0x03);
36
37 *status = 0;
38 if (s0 & (1 << 4))
39 *status |= FE_HAS_CARRIER;
40 if (s0 & (1 << 1))
41 *status |= FE_HAS_VITERBI;
42 if (s0 & (1 << 5))
43 *status |= FE_HAS_LOCK;
44 if (s1 & (1 << 1))
45 *status |= FE_HAS_SYNC;
46 if (s3 & (1 << 6))
47 *status |= FE_HAS_SIGNAL;
48
49 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
50 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
51 *status &= ~FE_HAS_LOCK;
52
53 return 0;
54}
55
56static int vp7045_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
57{
58 struct vp7045_fe_state *state = fe->demodulator_priv;
59 *ber = (vp7045_read_reg(state->d, 0x0D) << 16) |
60 (vp7045_read_reg(state->d, 0x0E) << 8) |
61 vp7045_read_reg(state->d, 0x0F);
62 return 0;
63}
64
65static int vp7045_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
66{
67 struct vp7045_fe_state *state = fe->demodulator_priv;
68 *unc = (vp7045_read_reg(state->d, 0x10) << 8) |
69 vp7045_read_reg(state->d, 0x11);
70 return 0;
71}
72
73static int vp7045_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
74{
75 struct vp7045_fe_state *state = fe->demodulator_priv;
76 u16 signal = (vp7045_read_reg(state->d, 0x14) << 8) |
77 vp7045_read_reg(state->d, 0x15);
78
79 *strength = ~signal;
80 return 0;
81}
82
83static int vp7045_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
84{
85 struct vp7045_fe_state *state = fe->demodulator_priv;
86 u8 _snr = vp7045_read_reg(state->d, 0x09);
87 *snr = (_snr << 8) | _snr;
88 return 0;
89}
90
91static int vp7045_fe_init(struct dvb_frontend* fe)
92{
93 return 0;
94}
95
96static int vp7045_fe_sleep(struct dvb_frontend* fe)
97{
98 return 0;
99}
100
101static int vp7045_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
102{
103 tune->min_delay_ms = 800;
104 return 0;
105}
106
107static int vp7045_fe_set_frontend(struct dvb_frontend* fe,
108 struct dvb_frontend_parameters *fep)
109{
110 struct vp7045_fe_state *state = fe->demodulator_priv;
111 u8 buf[5];
112 u32 freq = fep->frequency / 1000;
113
114 buf[0] = (freq >> 16) & 0xff;
115 buf[1] = (freq >> 8) & 0xff;
116 buf[2] = freq & 0xff;
117 buf[3] = 0;
118
119 switch (fep->u.ofdm.bandwidth) {
120 case BANDWIDTH_8_MHZ: buf[4] = 8; break;
121 case BANDWIDTH_7_MHZ: buf[4] = 7; break;
122 case BANDWIDTH_6_MHZ: buf[4] = 6; break;
123 case BANDWIDTH_AUTO: return -EOPNOTSUPP;
124 default:
125 return -EINVAL;
126 }
127
128 vp7045_usb_op(state->d,LOCK_TUNER_COMMAND,buf,5,NULL,0,200);
129 return 0;
130}
131
132static int vp7045_fe_get_frontend(struct dvb_frontend* fe,
133 struct dvb_frontend_parameters *fep)
134{
135 return 0;
136}
137
138static void vp7045_fe_release(struct dvb_frontend* fe)
139{
140 struct vp7045_fe_state *state = fe->demodulator_priv;
141 kfree(state);
142}
143
144static struct dvb_frontend_ops vp7045_fe_ops;
145
146struct dvb_frontend * vp7045_fe_attach(struct dvb_usb_device *d)
147{
148 struct vp7045_fe_state *s = kmalloc(sizeof(struct vp7045_fe_state), GFP_KERNEL);
149 if (s == NULL)
150 goto error;
151 memset(s,0,sizeof(struct vp7045_fe_state));
152
153 s->d = d;
154 s->fe.ops = &vp7045_fe_ops;
155 s->fe.demodulator_priv = s;
156
157 goto success;
158error:
159 return NULL;
160success:
161 return &s->fe;
162}
163
164
165static struct dvb_frontend_ops vp7045_fe_ops = {
166 .info = {
167 .name = "Twinhan VP7045/46 USB DVB-T",
168 .type = FE_OFDM,
169 .frequency_min = 44250000,
170 .frequency_max = 867250000,
171 .frequency_stepsize = 1000,
172 .caps = FE_CAN_INVERSION_AUTO |
173 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
174 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
175 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
176 FE_CAN_TRANSMISSION_MODE_AUTO |
177 FE_CAN_GUARD_INTERVAL_AUTO |
178 FE_CAN_RECOVER |
179 FE_CAN_HIERARCHY_AUTO,
180 },
181
182 .release = vp7045_fe_release,
183
184 .init = vp7045_fe_init,
185 .sleep = vp7045_fe_sleep,
186
187 .set_frontend = vp7045_fe_set_frontend,
188 .get_frontend = vp7045_fe_get_frontend,
189 .get_tune_settings = vp7045_fe_get_tune_settings,
190
191 .read_status = vp7045_fe_read_status,
192 .read_ber = vp7045_fe_read_ber,
193 .read_signal_strength = vp7045_fe_read_signal_strength,
194 .read_snr = vp7045_fe_read_snr,
195 .read_ucblocks = vp7045_fe_read_unc_blocks,
196};
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
new file mode 100644
index 000000000000..02ecc9a8e3b6
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -0,0 +1,263 @@
1/* DVB USB compliant Linux driver for the
2 * - TwinhanDTV Alpha/MagicBoxII USB2.0 DVB-T receiver
3 * - DigitalNow TinyUSB2 DVB-t receiver
4 *
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 *
7 * Thanks to Twinhan who kindly provided hardware and information.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation, version 2.
12 *
13 * see Documentation/dvb/README.dvb-usb for more information
14 */
15#include "vp7045.h"
16
17/* debug */
18int dvb_usb_vp7045_debug;
19module_param_named(debug,dvb_usb_vp7045_debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
21
22int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec)
23{
24 int ret = 0;
25 u8 inbuf[12] = { 0 }, outbuf[20] = { 0 };
26
27 outbuf[0] = cmd;
28
29 if (outlen > 19)
30 outlen = 19;
31
32 if (inlen > 11)
33 inlen = 11;
34
35 if (out != NULL && outlen > 0)
36 memcpy(&outbuf[1], out, outlen);
37
38 deb_xfer("out buffer: ");
39 debug_dump(outbuf,outlen+1,deb_xfer);
40
41 if ((ret = down_interruptible(&d->usb_sem)))
42 return ret;
43
44 if (usb_control_msg(d->udev,
45 usb_sndctrlpipe(d->udev,0),
46 TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0,
47 outbuf, 20, 2*HZ) != 20) {
48 err("USB control message 'out' went wrong.");
49 ret = -EIO;
50 goto unlock;
51 }
52
53 msleep(msec);
54
55 if (usb_control_msg(d->udev,
56 usb_rcvctrlpipe(d->udev,0),
57 TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
58 inbuf, 12, 2*HZ) != 12) {
59 err("USB control message 'in' went wrong.");
60 ret = -EIO;
61 goto unlock;
62 }
63
64 deb_xfer("in buffer: ");
65 debug_dump(inbuf,12,deb_xfer);
66
67 if (in != NULL && inlen > 0)
68 memcpy(in,&inbuf[1],inlen);
69
70unlock:
71 up(&d->usb_sem);
72
73 return ret;
74}
75
76u8 vp7045_read_reg(struct dvb_usb_device *d, u8 reg)
77{
78 u8 obuf[2] = { 0 },v;
79 obuf[1] = reg;
80
81 vp7045_usb_op(d,TUNER_REG_READ,obuf,2,&v,1,30);
82
83 return v;
84}
85
86static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
87{
88 u8 v = onoff;
89 return vp7045_usb_op(d,SET_TUNER_POWER,&v,1,NULL,0,150);
90}
91
92/* remote control stuff */
93
94/* The keymapping struct. Somehow this should be loaded to the driver, but
95 * currently it is hardcoded. */
96static struct dvb_usb_rc_key vp7045_rc_keys[] = {
97 /* insert the keys like this. to make the raw keys visible, enable
98 * debug=0x04 when loading dvb-usb-vp7045. */
99
100 /* these keys are probably wrong. I don't have a working IR-receiver on my
101 * vp7045, so I can't test it. Patches are welcome. */
102 { 0x00, 0x01, KEY_1 },
103 { 0x00, 0x02, KEY_2 },
104};
105
106static int vp7045_rc_query(struct dvb_usb_device *d, u32 *key_buf, int *state)
107{
108 u8 key;
109 int i;
110 vp7045_usb_op(d,RC_VAL_READ,NULL,0,&key,1,20);
111
112 deb_rc("remote query key: %x %d\n",key,key);
113
114 if (key == 0x44) {
115 *state = REMOTE_NO_KEY_PRESSED;
116 return 0;
117 }
118
119 for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++)
120 if (vp7045_rc_keys[i].data == key) {
121 *state = REMOTE_KEY_PRESSED;
122 *key_buf = vp7045_rc_keys[i].event;
123 break;
124 }
125 return 0;
126}
127
128static int vp7045_read_eeprom(struct dvb_usb_device *d,u8 *buf, int len, int offset)
129{
130 int i = 0;
131 u8 v,br[2];
132 for (i=0; i < len; i++) {
133 v = offset + i;
134 vp7045_usb_op(d,GET_EE_VALUE,&v,1,br,2,5);
135 buf[i] = br[1];
136 }
137 deb_info("VP7045 EEPROM read (offs: %d, len: %d) : ",offset, i);
138 debug_dump(buf,i,deb_info);
139 return 0;
140}
141
142
143static int vp7045_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
144{
145 return vp7045_read_eeprom(d,mac, 6, MAC_0_ADDR);
146}
147
148static int vp7045_frontend_attach(struct dvb_usb_device *d)
149{
150 u8 buf[255] = { 0 };
151
152 vp7045_usb_op(d,VENDOR_STRING_READ,NULL,0,buf,20,0);
153 buf[10] = '\0';
154 deb_info("firmware says: %s ",buf);
155
156 vp7045_usb_op(d,PRODUCT_STRING_READ,NULL,0,buf,20,0);
157 buf[10] = '\0';
158 deb_info("%s ",buf);
159
160 vp7045_usb_op(d,FW_VERSION_READ,NULL,0,buf,20,0);
161 buf[10] = '\0';
162 deb_info("v%s\n",buf);
163
164/* Dump the EEPROM */
165/* vp7045_read_eeprom(d,buf, 255, FX2_ID_ADDR); */
166
167 d->fe = vp7045_fe_attach(d);
168
169 return 0;
170}
171
172static struct dvb_usb_properties vp7045_properties;
173
174static int vp7045_usb_probe(struct usb_interface *intf,
175 const struct usb_device_id *id)
176{
177 return dvb_usb_device_init(intf,&vp7045_properties,THIS_MODULE);
178}
179
180static struct usb_device_id vp7045_usb_table [] = {
181 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_COLD) },
182 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_WARM) },
183 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_COLD) },
184 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_WARM) },
185 { 0 },
186};
187MODULE_DEVICE_TABLE(usb, vp7045_usb_table);
188
189static struct dvb_usb_properties vp7045_properties = {
190 .caps = 0,
191
192 .usb_ctrl = CYPRESS_FX2,
193 .firmware = "dvb-usb-vp7045-01.fw",
194
195 .power_ctrl = vp7045_power_ctrl,
196 .frontend_attach = vp7045_frontend_attach,
197 .read_mac_address = vp7045_read_mac_addr,
198
199 .rc_interval = 400,
200 .rc_key_map = vp7045_rc_keys,
201 .rc_key_map_size = ARRAY_SIZE(vp7045_rc_keys),
202 .rc_query = vp7045_rc_query,
203
204 /* parameter for the MPEG2-data transfer */
205 .urb = {
206 .type = DVB_USB_BULK,
207 .count = 7,
208 .endpoint = 0x02,
209 .u = {
210 .bulk = {
211 .buffersize = 4096,
212 }
213 }
214 },
215
216 .num_device_descs = 2,
217 .devices = {
218 { .name = "Twinhan USB2.0 DVB-T receiver (TwinhanDTV Alpha/MagicBox II)",
219 .cold_ids = { &vp7045_usb_table[0], NULL },
220 .warm_ids = { &vp7045_usb_table[1], NULL },
221 },
222 { .name = "DigitalNow TinyUSB 2 DVB-t Receiver",
223 .cold_ids = { &vp7045_usb_table[2], NULL },
224 .warm_ids = { &vp7045_usb_table[3], NULL },
225 },
226 { 0 },
227 }
228};
229
230/* usb specific object needed to register this driver with the usb subsystem */
231static struct usb_driver vp7045_usb_driver = {
232 .owner = THIS_MODULE,
233 .name = "dvb-usb-vp7045",
234 .probe = vp7045_usb_probe,
235 .disconnect = dvb_usb_device_exit,
236 .id_table = vp7045_usb_table,
237};
238
239/* module stuff */
240static int __init vp7045_usb_module_init(void)
241{
242 int result;
243 if ((result = usb_register(&vp7045_usb_driver))) {
244 err("usb_register failed. (%d)",result);
245 return result;
246 }
247
248 return 0;
249}
250
251static void __exit vp7045_usb_module_exit(void)
252{
253 /* deregister this driver from the USB subsystem */
254 usb_deregister(&vp7045_usb_driver);
255}
256
257module_init(vp7045_usb_module_init);
258module_exit(vp7045_usb_module_exit);
259
260MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
261MODULE_DESCRIPTION("Driver for Twinhan MagicBox/Alpha and DNTV tinyUSB2 DVB-T USB2.0");
262MODULE_VERSION("1.0");
263MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/vp7045.h b/drivers/media/dvb/dvb-usb/vp7045.h
new file mode 100644
index 000000000000..9ce21a20fa86
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/vp7045.h
@@ -0,0 +1,78 @@
1/* Common header-file of the Linux driver for the TwinhanDTV Alpha/MagicBoxII
2 * USB2.0 DVB-T receiver.
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 *
6 * Thanks to Twinhan who kindly provided hardware and information.
7 *
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.
11 *
12 * see Documentation/dvb/README.dvb-usb for more information
13 */
14#ifndef _DVB_USB_VP7045_H_
15#define _DVB_USB_VP7045_H_
16
17#define DVB_USB_LOG_PREFIX "vp7045"
18#include "dvb-usb.h"
19
20extern int dvb_usb_vp7045_debug;
21#define deb_info(args...) dprintk(dvb_usb_vp7045_debug,0x01,args)
22#define deb_xfer(args...) dprintk(dvb_usb_vp7045_debug,0x02,args)
23#define deb_rc(args...) dprintk(dvb_usb_vp7045_debug,0x04,args)
24
25/* vp7045 commands */
26
27/* Twinhan Vendor requests */
28#define TH_COMMAND_IN 0xC0
29#define TH_COMMAND_OUT 0xC1
30
31/* command bytes */
32#define TUNER_REG_READ 0x03
33#define TUNER_REG_WRITE 0x04
34
35#define RC_VAL_READ 0x05
36 #define RC_NO_KEY 0x44
37
38#define SET_TUNER_POWER 0x06
39#define CHECK_TUNER_POWER 0x12
40 #define Tuner_Power_ON 1
41 #define Tuner_Power_OFF 0
42
43#define GET_USB_SPEED 0x07
44 #define USB_SPEED_LOW 0
45 #define USB_SPEED_FULL 1
46 #define USB_SPEED_HIGH 2
47
48#define LOCK_TUNER_COMMAND 0x09
49
50#define TUNER_SIGNAL_READ 0x0A
51
52/* FX2 eeprom */
53#define SET_EE_VALUE 0x10
54#define GET_EE_VALUE 0x11
55 #define FX2_ID_ADDR 0x00
56 #define VID_MSB_ADDR 0x02
57 #define VID_LSB_ADDR 0x01
58 #define PID_MSB_ADDR 0x04
59 #define PID_LSB_ADDR 0x03
60 #define MAC_0_ADDR 0x07
61 #define MAC_1_ADDR 0x08
62 #define MAC_2_ADDR 0x09
63 #define MAC_3_ADDR 0x0a
64 #define MAC_4_ADDR 0x0b
65 #define MAC_5_ADDR 0x0c
66
67#define RESET_FX2 0x13
68
69#define FW_VERSION_READ 0x0B
70#define VENDOR_STRING_READ 0x0C
71#define PRODUCT_STRING_READ 0x0D
72#define FW_BCD_VERSION_READ 0x14
73
74extern struct dvb_frontend * vp7045_fe_attach(struct dvb_usb_device *d);
75extern int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen,int msec);
76extern u8 vp7045_read_reg(struct dvb_usb_device *d, u8 reg);
77
78#endif
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 0bfd4df17d08..b4fddf513ebe 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -12,10 +12,10 @@ config DVB_STV0299
12 12
13config DVB_CX24110 13config DVB_CX24110
14 tristate "Conexant CX24110 based" 14 tristate "Conexant CX24110 based"
15 depends on DVB_CORE 15 depends on DVB_CORE
16 help 16 help
17 A DVB-S tuner module. Say Y when you want to support this frontend. 17 A DVB-S tuner module. Say Y when you want to support this frontend.
18 18
19config DVB_TDA8083 19config DVB_TDA8083
20 tristate "Philips TDA8083 based" 20 tristate "Philips TDA8083 based"
21 depends on DVB_CORE 21 depends on DVB_CORE
@@ -127,8 +127,8 @@ comment "DVB-C (cable) frontends"
127config DVB_ATMEL_AT76C651 127config DVB_ATMEL_AT76C651
128 tristate "Atmel AT76C651 based" 128 tristate "Atmel AT76C651 based"
129 depends on DVB_CORE 129 depends on DVB_CORE
130 help 130 help
131 A DVB-C tuner module. Say Y when you want to support this frontend. 131 A DVB-C tuner module. Say Y when you want to support this frontend.
132 132
133config DVB_VES1820 133config DVB_VES1820
134 tristate "VLSI VES1820 based" 134 tristate "VLSI VES1820 based"
@@ -158,10 +158,6 @@ config DVB_NXT2002
158 help 158 help
159 An ATSC 8VSB tuner module. Say Y when you want to support this frontend. 159 An ATSC 8VSB tuner module. Say Y when you want to support this frontend.
160 160
161config DVB_OR51132
162 tristate "OR51132 based (pcHDTV)"
163 depends on DVB_CORE
164
165config DVB_OR51211 161config DVB_OR51211
166 tristate "or51211 based (pcHDTV HD2000 card)" 162 tristate "or51211 based (pcHDTV HD2000 card)"
167 depends on DVB_CORE 163 depends on DVB_CORE
@@ -169,4 +165,20 @@ config DVB_OR51211
169 help 165 help
170 An ATSC 8VSB tuner module. Say Y when you want to support this frontend. 166 An ATSC 8VSB tuner module. Say Y when you want to support this frontend.
171 167
168config DVB_OR51132
169 tristate "OR51132 based (pcHDTV HD3000 card)"
170 depends on DVB_CORE
171 select FW_LOADER
172 help
173 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
174 to support this frontend.
175
176config DVB_BCM3510
177 tristate "Broadcom BCM3510"
178 depends on DVB_CORE
179 select FW_LOADER
180 help
181 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to
182 support this frontend.
183
172endmenu 184endmenu
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 7f8784870eab..91d6d3576d3d 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -28,3 +28,4 @@ obj-$(CONFIG_DVB_STV0297) += stv0297.o
28obj-$(CONFIG_DVB_NXT2002) += nxt2002.o 28obj-$(CONFIG_DVB_NXT2002) += nxt2002.o
29obj-$(CONFIG_DVB_OR51211) += or51211.o 29obj-$(CONFIG_DVB_OR51211) += or51211.o
30obj-$(CONFIG_DVB_OR51132) += or51132.o 30obj-$(CONFIG_DVB_OR51132) += or51132.o
31obj-$(CONFIG_DVB_BCM3510) += bcm3510.o
diff --git a/drivers/media/dvb/frontends/at76c651.c b/drivers/media/dvb/frontends/at76c651.c
index ce2eaa1640e8..72a2b5455b0b 100644
--- a/drivers/media/dvb/frontends/at76c651.c
+++ b/drivers/media/dvb/frontends/at76c651.c
@@ -259,7 +259,7 @@ static int at76c651_set_parameters(struct dvb_frontend* fe,
259 struct dvb_frontend_parameters *p) 259 struct dvb_frontend_parameters *p)
260{ 260{
261 int ret; 261 int ret;
262 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 262 struct at76c651_state* state = fe->demodulator_priv;
263 263
264 at76c651_writereg(state, 0x0c, 0xc3); 264 at76c651_writereg(state, 0x0c, 0xc3);
265 state->config->pll_set(fe, p); 265 state->config->pll_set(fe, p);
@@ -276,7 +276,7 @@ static int at76c651_set_parameters(struct dvb_frontend* fe,
276 276
277static int at76c651_set_defaults(struct dvb_frontend* fe) 277static int at76c651_set_defaults(struct dvb_frontend* fe)
278{ 278{
279 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 279 struct at76c651_state* state = fe->demodulator_priv;
280 280
281 at76c651_set_symbol_rate(state, 6900000); 281 at76c651_set_symbol_rate(state, 6900000);
282 at76c651_set_qam(state, QAM_64); 282 at76c651_set_qam(state, QAM_64);
@@ -294,7 +294,7 @@ static int at76c651_set_defaults(struct dvb_frontend* fe)
294 294
295static int at76c651_read_status(struct dvb_frontend* fe, fe_status_t* status) 295static int at76c651_read_status(struct dvb_frontend* fe, fe_status_t* status)
296{ 296{
297 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 297 struct at76c651_state* state = fe->demodulator_priv;
298 u8 sync; 298 u8 sync;
299 299
300 /* 300 /*
@@ -319,7 +319,7 @@ static int at76c651_read_status(struct dvb_frontend* fe, fe_status_t* status)
319 319
320static int at76c651_read_ber(struct dvb_frontend* fe, u32* ber) 320static int at76c651_read_ber(struct dvb_frontend* fe, u32* ber)
321{ 321{
322 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 322 struct at76c651_state* state = fe->demodulator_priv;
323 323
324 *ber = (at76c651_readreg(state, 0x81) & 0x0F) << 16; 324 *ber = (at76c651_readreg(state, 0x81) & 0x0F) << 16;
325 *ber |= at76c651_readreg(state, 0x82) << 8; 325 *ber |= at76c651_readreg(state, 0x82) << 8;
@@ -331,7 +331,7 @@ static int at76c651_read_ber(struct dvb_frontend* fe, u32* ber)
331 331
332static int at76c651_read_signal_strength(struct dvb_frontend* fe, u16* strength) 332static int at76c651_read_signal_strength(struct dvb_frontend* fe, u16* strength)
333{ 333{
334 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 334 struct at76c651_state* state = fe->demodulator_priv;
335 335
336 u8 gain = ~at76c651_readreg(state, 0x91); 336 u8 gain = ~at76c651_readreg(state, 0x91);
337 *strength = (gain << 8) | gain; 337 *strength = (gain << 8) | gain;
@@ -341,7 +341,7 @@ static int at76c651_read_signal_strength(struct dvb_frontend* fe, u16* strength)
341 341
342static int at76c651_read_snr(struct dvb_frontend* fe, u16* snr) 342static int at76c651_read_snr(struct dvb_frontend* fe, u16* snr)
343{ 343{
344 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 344 struct at76c651_state* state = fe->demodulator_priv;
345 345
346 *snr = 0xFFFF - 346 *snr = 0xFFFF -
347 ((at76c651_readreg(state, 0x8F) << 8) | 347 ((at76c651_readreg(state, 0x8F) << 8) |
@@ -352,7 +352,7 @@ static int at76c651_read_snr(struct dvb_frontend* fe, u16* snr)
352 352
353static int at76c651_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 353static int at76c651_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
354{ 354{
355 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 355 struct at76c651_state* state = fe->demodulator_priv;
356 356
357 *ucblocks = at76c651_readreg(state, 0x82); 357 *ucblocks = at76c651_readreg(state, 0x82);
358 358
@@ -369,7 +369,7 @@ static int at76c651_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronte
369 369
370static void at76c651_release(struct dvb_frontend* fe) 370static void at76c651_release(struct dvb_frontend* fe)
371{ 371{
372 struct at76c651_state* state = (struct at76c651_state*) fe->demodulator_priv; 372 struct at76c651_state* state = fe->demodulator_priv;
373 kfree(state); 373 kfree(state);
374} 374}
375 375
@@ -381,7 +381,7 @@ struct dvb_frontend* at76c651_attach(const struct at76c651_config* config,
381 struct at76c651_state* state = NULL; 381 struct at76c651_state* state = NULL;
382 382
383 /* allocate memory for the internal state */ 383 /* allocate memory for the internal state */
384 state = (struct at76c651_state*) kmalloc(sizeof(struct at76c651_state), GFP_KERNEL); 384 state = kmalloc(sizeof(struct at76c651_state), GFP_KERNEL);
385 if (state == NULL) goto error; 385 if (state == NULL) goto error;
386 386
387 /* setup the state */ 387 /* setup the state */
diff --git a/drivers/media/dvb/frontends/bcm3510.c b/drivers/media/dvb/frontends/bcm3510.c
new file mode 100644
index 000000000000..f5fdc5c3e605
--- /dev/null
+++ b/drivers/media/dvb/frontends/bcm3510.c
@@ -0,0 +1,853 @@
1/*
2 * Support for the Broadcom BCM3510 ATSC demodulator (1st generation Air2PC)
3 *
4 * Copyright (C) 2001-5, B2C2 inc.
5 *
6 * GPL/Linux driver written by Patrick Boettcher <patrick.boettcher@desy.de>
7 *
8 * This driver is "hard-coded" to be used with the 1st generation of
9 * Technisat/B2C2's Air2PC ATSC PCI/USB cards/boxes. The pll-programming
10 * (Panasonic CT10S) is located here, which is actually wrong. Unless there is
11 * another device with a BCM3510, this is no problem.
12 *
13 * The driver works also with QAM64 DVB-C, but had an unreasonable high
14 * UNC. (Tested with the Air2PC ATSC 1st generation)
15 *
16 * You'll need a firmware for this driver in order to get it running. It is
17 * called "dvb-fe-bcm3510-01.fw".
18 *
19 * This program is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by the Free
21 * Software Foundation; either version 2 of the License, or (at your option)
22 * any later version.
23 *
24 * This program is distributed in the hope that it will be useful, but WITHOUT
25 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
27 * more details.
28 *
29 * You should have received a copy of the GNU General Public License along with
30 * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
31 * Ave, Cambridge, MA 02139, USA.
32 */
33
34#include <linux/init.h>
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/device.h>
38#include <linux/firmware.h>
39
40#include "dvb_frontend.h"
41#include "bcm3510.h"
42#include "bcm3510_priv.h"
43
44struct bcm3510_state {
45
46 struct i2c_adapter* i2c;
47 struct dvb_frontend_ops ops;
48 const struct bcm3510_config* config;
49 struct dvb_frontend frontend;
50
51 /* demodulator private data */
52 struct semaphore hab_sem;
53 u8 firmware_loaded:1;
54
55 unsigned long next_status_check;
56 unsigned long status_check_interval;
57 struct bcm3510_hab_cmd_status1 status1;
58 struct bcm3510_hab_cmd_status2 status2;
59};
60
61static int debug;
62module_param(debug, int, 0644);
63MODULE_PARM_DESC(debug, "set debugging level (1=info,2=i2c (|-able)).");
64
65#define dprintk(level,x...) if (level & debug) printk(x)
66#define dbufout(b,l,m) {\
67 int i; \
68 for (i = 0; i < l; i++) \
69 m("%02x ",b[i]); \
70}
71#define deb_info(args...) dprintk(0x01,args)
72#define deb_i2c(args...) dprintk(0x02,args)
73#define deb_hab(args...) dprintk(0x04,args)
74
75/* transfer functions */
76static int bcm3510_writebytes (struct bcm3510_state *state, u8 reg, u8 *buf, u8 len)
77{
78 u8 b[256];
79 int err;
80 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = b, .len = len + 1 };
81
82 b[0] = reg;
83 memcpy(&b[1],buf,len);
84
85 deb_i2c("i2c wr %02x: ",reg);
86 dbufout(buf,len,deb_i2c);
87 deb_i2c("\n");
88
89 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
90
91 deb_info("%s: i2c write error (addr %02x, reg %02x, err == %i)\n",
92 __FUNCTION__, state->config->demod_address, reg, err);
93 return -EREMOTEIO;
94 }
95
96 return 0;
97}
98
99static int bcm3510_readbytes (struct bcm3510_state *state, u8 reg, u8 *buf, u8 len)
100{
101 struct i2c_msg msg[] = {
102 { .addr = state->config->demod_address, .flags = 0, .buf = &reg, .len = 1 },
103 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = buf, .len = len }
104 };
105 int err;
106
107 memset(buf,0,len);
108
109 if ((err = i2c_transfer (state->i2c, msg, 2)) != 2) {
110 deb_info("%s: i2c read error (addr %02x, reg %02x, err == %i)\n",
111 __FUNCTION__, state->config->demod_address, reg, err);
112 return -EREMOTEIO;
113 }
114 deb_i2c("i2c rd %02x: ",reg);
115 dbufout(buf,len,deb_i2c);
116 deb_i2c("\n");
117
118 return 0;
119}
120
121static int bcm3510_writeB(struct bcm3510_state *state, u8 reg, bcm3510_register_value v)
122{
123 return bcm3510_writebytes(state,reg,&v.raw,1);
124}
125
126static int bcm3510_readB(struct bcm3510_state *state, u8 reg, bcm3510_register_value *v)
127{
128 return bcm3510_readbytes(state,reg,&v->raw,1);
129}
130
131/* Host Access Buffer transfers */
132static int bcm3510_hab_get_response(struct bcm3510_state *st, u8 *buf, int len)
133{
134 bcm3510_register_value v;
135 int ret,i;
136
137 v.HABADR_a6.HABADR = 0;
138 if ((ret = bcm3510_writeB(st,0xa6,v)) < 0)
139 return ret;
140
141 for (i = 0; i < len; i++) {
142 if ((ret = bcm3510_readB(st,0xa7,&v)) < 0)
143 return ret;
144 buf[i] = v.HABDATA_a7;
145 }
146 return 0;
147}
148
149static int bcm3510_hab_send_request(struct bcm3510_state *st, u8 *buf, int len)
150{
151 bcm3510_register_value v,hab;
152 int ret,i;
153 unsigned long t;
154
155/* Check if any previous HAB request still needs to be serviced by the
156 * Aquisition Processor before sending new request */
157 if ((ret = bcm3510_readB(st,0xa8,&v)) < 0)
158 return ret;
159 if (v.HABSTAT_a8.HABR) {
160 deb_info("HAB is running already - clearing it.\n");
161 v.HABSTAT_a8.HABR = 0;
162 bcm3510_writeB(st,0xa8,v);
163// return -EBUSY;
164 }
165
166/* Send the start HAB Address (automatically incremented after write of
167 * HABDATA) and write the HAB Data */
168 hab.HABADR_a6.HABADR = 0;
169 if ((ret = bcm3510_writeB(st,0xa6,hab)) < 0)
170 return ret;
171
172 for (i = 0; i < len; i++) {
173 hab.HABDATA_a7 = buf[i];
174 if ((ret = bcm3510_writeB(st,0xa7,hab)) < 0)
175 return ret;
176 }
177
178/* Set the HABR bit to indicate AP request in progress (LBHABR allows HABR to
179 * be written) */
180 v.raw = 0; v.HABSTAT_a8.HABR = 1; v.HABSTAT_a8.LDHABR = 1;
181 if ((ret = bcm3510_writeB(st,0xa8,v)) < 0)
182 return ret;
183
184/* Polling method: Wait until the AP finishes processing the HAB request */
185 t = jiffies + 1*HZ;
186 while (time_before(jiffies, t)) {
187 deb_info("waiting for HAB to complete\n");
188 msleep(10);
189 if ((ret = bcm3510_readB(st,0xa8,&v)) < 0)
190 return ret;
191
192 if (!v.HABSTAT_a8.HABR)
193 return 0;
194 }
195
196 deb_info("send_request execution timed out.\n");
197 return -ETIMEDOUT;
198}
199
200static int bcm3510_do_hab_cmd(struct bcm3510_state *st, u8 cmd, u8 msgid, u8 *obuf, u8 olen, u8 *ibuf, u8 ilen)
201{
202 u8 ob[olen+2],ib[ilen+2];
203 int ret = 0;
204
205 ob[0] = cmd;
206 ob[1] = msgid;
207 memcpy(&ob[2],obuf,olen);
208
209 deb_hab("hab snd: ");
210 dbufout(ob,olen+2,deb_hab);
211 deb_hab("\n");
212
213 if (down_interruptible(&st->hab_sem) < 0)
214 return -EAGAIN;
215
216 if ((ret = bcm3510_hab_send_request(st, ob, olen+2)) < 0 ||
217 (ret = bcm3510_hab_get_response(st, ib, ilen+2)) < 0)
218 goto error;
219
220 deb_hab("hab get: ");
221 dbufout(ib,ilen+2,deb_hab);
222 deb_hab("\n");
223
224 memcpy(ibuf,&ib[2],ilen);
225error:
226 up(&st->hab_sem);
227 return ret;
228}
229
230#if 0
231/* not needed, we use a semaphore to prevent HAB races */
232static int bcm3510_is_ap_ready(struct bcm3510_state *st)
233{
234 bcm3510_register_value ap,hab;
235 int ret;
236
237 if ((ret = bcm3510_readB(st,0xa8,&hab)) < 0 ||
238 (ret = bcm3510_readB(st,0xa2,&ap) < 0))
239 return ret;
240
241 if (ap.APSTAT1_a2.RESET || ap.APSTAT1_a2.IDLE || ap.APSTAT1_a2.STOP || hab.HABSTAT_a8.HABR) {
242 deb_info("AP is busy\n");
243 return -EBUSY;
244 }
245
246 return 0;
247}
248#endif
249
250static int bcm3510_bert_reset(struct bcm3510_state *st)
251{
252 bcm3510_register_value b;
253 int ret;
254
255 if ((ret < bcm3510_readB(st,0xfa,&b)) < 0)
256 return ret;
257
258 b.BERCTL_fa.RESYNC = 0; bcm3510_writeB(st,0xfa,b);
259 b.BERCTL_fa.RESYNC = 1; bcm3510_writeB(st,0xfa,b);
260 b.BERCTL_fa.RESYNC = 0; bcm3510_writeB(st,0xfa,b);
261 b.BERCTL_fa.CNTCTL = 1; b.BERCTL_fa.BITCNT = 1; bcm3510_writeB(st,0xfa,b);
262
263 /* clear residual bit counter TODO */
264 return 0;
265}
266
267static int bcm3510_refresh_state(struct bcm3510_state *st)
268{
269 if (time_after(jiffies,st->next_status_check)) {
270 bcm3510_do_hab_cmd(st, CMD_STATUS, MSGID_STATUS1, NULL,0, (u8 *)&st->status1, sizeof(st->status1));
271 bcm3510_do_hab_cmd(st, CMD_STATUS, MSGID_STATUS2, NULL,0, (u8 *)&st->status2, sizeof(st->status2));
272 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
273 }
274 return 0;
275}
276
277static int bcm3510_read_status(struct dvb_frontend *fe, fe_status_t *status)
278{
279 struct bcm3510_state* st = fe->demodulator_priv;
280 bcm3510_refresh_state(st);
281
282 *status = 0;
283 if (st->status1.STATUS1.RECEIVER_LOCK)
284 *status |= FE_HAS_LOCK | FE_HAS_SYNC;
285
286 if (st->status1.STATUS1.FEC_LOCK)
287 *status |= FE_HAS_VITERBI;
288
289 if (st->status1.STATUS1.OUT_PLL_LOCK)
290 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
291
292 if (*status & FE_HAS_LOCK)
293 st->status_check_interval = 1500;
294 else /* more frequently checks if no lock has been achieved yet */
295 st->status_check_interval = 500;
296
297 deb_info("real_status: %02x\n",*status);
298 return 0;
299}
300
301static int bcm3510_read_ber(struct dvb_frontend* fe, u32* ber)
302{
303 struct bcm3510_state* st = fe->demodulator_priv;
304 bcm3510_refresh_state(st);
305
306 *ber = (st->status2.LDBER0 << 16) | (st->status2.LDBER1 << 8) | st->status2.LDBER2;
307 return 0;
308}
309
310static int bcm3510_read_unc(struct dvb_frontend* fe, u32* unc)
311{
312 struct bcm3510_state* st = fe->demodulator_priv;
313 bcm3510_refresh_state(st);
314 *unc = (st->status2.LDUERC0 << 8) | st->status2.LDUERC1;
315 return 0;
316}
317
318static int bcm3510_read_signal_strength(struct dvb_frontend* fe, u16* strength)
319{
320 struct bcm3510_state* st = fe->demodulator_priv;
321 s32 t;
322
323 bcm3510_refresh_state(st);
324 t = st->status2.SIGNAL;
325
326 if (t > 190)
327 t = 190;
328 if (t < 90)
329 t = 90;
330
331 t -= 90;
332 t = t * 0xff / 100;
333 /* normalize if necessary */
334 *strength = (t << 8) | t;
335 return 0;
336}
337
338static int bcm3510_read_snr(struct dvb_frontend* fe, u16* snr)
339{
340 struct bcm3510_state* st = fe->demodulator_priv;
341 bcm3510_refresh_state(st);
342
343 *snr = st->status1.SNR_EST0*1000 + ((st->status1.SNR_EST1*1000) >> 8);
344 return 0;
345}
346
347/* tuner frontend programming */
348static int bcm3510_tuner_cmd(struct bcm3510_state* st,u8 bc, u16 n, u8 a)
349{
350 struct bcm3510_hab_cmd_tune c;
351 memset(&c,0,sizeof(struct bcm3510_hab_cmd_tune));
352
353/* I2C Mode disabled, set 16 control / Data pairs */
354 c.length = 0x10;
355 c.clock_width = 0;
356/* CS1, CS0, DATA, CLK bits control the tuner RF_AGC_SEL pin is set to
357 * logic high (as Configuration) */
358 c.misc = 0x10;
359/* Set duration of the initial state of TUNCTL = 3.34 micro Sec */
360 c.TUNCTL_state = 0x40;
361
362/* PRESCALER DEVIDE RATIO | BC1_2_3_4; (band switch), 1stosc REFERENCE COUNTER REF_S12 and REF_S11 */
363 c.ctl_dat[0].ctrl.size = BITS_8;
364 c.ctl_dat[0].data = 0x80 | bc;
365
366/* Control DATA pin, 1stosc REFERENCE COUNTER REF_S10 to REF_S3 */
367 c.ctl_dat[1].ctrl.size = BITS_8;
368 c.ctl_dat[1].data = 4;
369
370/* set CONTROL BIT 1 to 1, 1stosc REFERENCE COUNTER REF_S2 to REF_S1 */
371 c.ctl_dat[2].ctrl.size = BITS_3;
372 c.ctl_dat[2].data = 0x20;
373
374/* control CS0 pin, pulse byte ? */
375 c.ctl_dat[3].ctrl.size = BITS_3;
376 c.ctl_dat[3].ctrl.clk_off = 1;
377 c.ctl_dat[3].ctrl.cs0 = 1;
378 c.ctl_dat[3].data = 0x40;
379
380/* PGM_S18 to PGM_S11 */
381 c.ctl_dat[4].ctrl.size = BITS_8;
382 c.ctl_dat[4].data = n >> 3;
383
384/* PGM_S10 to PGM_S8, SWL_S7 to SWL_S3 */
385 c.ctl_dat[5].ctrl.size = BITS_8;
386 c.ctl_dat[5].data = ((n & 0x7) << 5) | (a >> 2);
387
388/* SWL_S2 and SWL_S1, set CONTROL BIT 2 to 0 */
389 c.ctl_dat[6].ctrl.size = BITS_3;
390 c.ctl_dat[6].data = (a << 6) & 0xdf;
391
392/* control CS0 pin, pulse byte ? */
393 c.ctl_dat[7].ctrl.size = BITS_3;
394 c.ctl_dat[7].ctrl.clk_off = 1;
395 c.ctl_dat[7].ctrl.cs0 = 1;
396 c.ctl_dat[7].data = 0x40;
397
398/* PRESCALER DEVIDE RATIO, 2ndosc REFERENCE COUNTER REF_S12 and REF_S11 */
399 c.ctl_dat[8].ctrl.size = BITS_8;
400 c.ctl_dat[8].data = 0x80;
401
402/* 2ndosc REFERENCE COUNTER REF_S10 to REF_S3 */
403 c.ctl_dat[9].ctrl.size = BITS_8;
404 c.ctl_dat[9].data = 0x10;
405
406/* set CONTROL BIT 1 to 1, 2ndosc REFERENCE COUNTER REF_S2 to REF_S1 */
407 c.ctl_dat[10].ctrl.size = BITS_3;
408 c.ctl_dat[10].data = 0x20;
409
410/* pulse byte */
411 c.ctl_dat[11].ctrl.size = BITS_3;
412 c.ctl_dat[11].ctrl.clk_off = 1;
413 c.ctl_dat[11].ctrl.cs1 = 1;
414 c.ctl_dat[11].data = 0x40;
415
416/* PGM_S18 to PGM_S11 */
417 c.ctl_dat[12].ctrl.size = BITS_8;
418 c.ctl_dat[12].data = 0x2a;
419
420/* PGM_S10 to PGM_S8 and SWL_S7 to SWL_S3 */
421 c.ctl_dat[13].ctrl.size = BITS_8;
422 c.ctl_dat[13].data = 0x8e;
423
424/* SWL_S2 and SWL_S1 and set CONTROL BIT 2 to 0 */
425 c.ctl_dat[14].ctrl.size = BITS_3;
426 c.ctl_dat[14].data = 0;
427
428/* Pulse Byte */
429 c.ctl_dat[15].ctrl.size = BITS_3;
430 c.ctl_dat[15].ctrl.clk_off = 1;
431 c.ctl_dat[15].ctrl.cs1 = 1;
432 c.ctl_dat[15].data = 0x40;
433
434 return bcm3510_do_hab_cmd(st,CMD_TUNE, MSGID_TUNE,(u8 *) &c,sizeof(c), NULL, 0);
435}
436
437static int bcm3510_set_freq(struct bcm3510_state* st,u32 freq)
438{
439 u8 bc,a;
440 u16 n;
441 s32 YIntercept,Tfvco1;
442
443 freq /= 1000;
444
445 deb_info("%dkHz:",freq);
446 /* set Band Switch */
447 if (freq <= 168000)
448 bc = 0x1c;
449 else if (freq <= 378000)
450 bc = 0x2c;
451 else
452 bc = 0x30;
453
454 if (freq >= 470000) {
455 freq -= 470001;
456 YIntercept = 18805;
457 } else if (freq >= 90000) {
458 freq -= 90001;
459 YIntercept = 15005;
460 } else if (freq >= 76000){
461 freq -= 76001;
462 YIntercept = 14865;
463 } else {
464 freq -= 54001;
465 YIntercept = 14645;
466 }
467
468 Tfvco1 = (((freq/6000)*60 + YIntercept)*4)/10;
469
470 n = Tfvco1 >> 6;
471 a = Tfvco1 & 0x3f;
472
473 deb_info(" BC1_2_3_4: %x, N: %x A: %x\n", bc, n, a);
474 if (n >= 16 && n <= 2047)
475 return bcm3510_tuner_cmd(st,bc,n,a);
476
477 return -EINVAL;
478}
479
480static int bcm3510_set_frontend(struct dvb_frontend* fe,
481 struct dvb_frontend_parameters *p)
482{
483 struct bcm3510_state* st = fe->demodulator_priv;
484 struct bcm3510_hab_cmd_ext_acquire cmd;
485 struct bcm3510_hab_cmd_bert_control bert;
486 int ret;
487
488 memset(&cmd,0,sizeof(cmd));
489 switch (p->u.vsb.modulation) {
490 case QAM_256:
491 cmd.ACQUIRE0.MODE = 0x1;
492 cmd.ACQUIRE1.SYM_RATE = 0x1;
493 cmd.ACQUIRE1.IF_FREQ = 0x1;
494 break;
495 case QAM_64:
496 cmd.ACQUIRE0.MODE = 0x2;
497 cmd.ACQUIRE1.SYM_RATE = 0x2;
498 cmd.ACQUIRE1.IF_FREQ = 0x1;
499 break;
500/* case QAM_256:
501 cmd.ACQUIRE0.MODE = 0x3;
502 break;
503 case QAM_128:
504 cmd.ACQUIRE0.MODE = 0x4;
505 break;
506 case QAM_64:
507 cmd.ACQUIRE0.MODE = 0x5;
508 break;
509 case QAM_32:
510 cmd.ACQUIRE0.MODE = 0x6;
511 break;
512 case QAM_16:
513 cmd.ACQUIRE0.MODE = 0x7;
514 break;*/
515 case VSB_8:
516 cmd.ACQUIRE0.MODE = 0x8;
517 cmd.ACQUIRE1.SYM_RATE = 0x0;
518 cmd.ACQUIRE1.IF_FREQ = 0x0;
519 break;
520 case VSB_16:
521 cmd.ACQUIRE0.MODE = 0x9;
522 cmd.ACQUIRE1.SYM_RATE = 0x0;
523 cmd.ACQUIRE1.IF_FREQ = 0x0;
524 default:
525 return -EINVAL;
526 };
527 cmd.ACQUIRE0.OFFSET = 0;
528 cmd.ACQUIRE0.NTSCSWEEP = 1;
529 cmd.ACQUIRE0.FA = 1;
530 cmd.ACQUIRE0.BW = 0;
531
532/* if (enableOffset) {
533 cmd.IF_OFFSET0 = xx;
534 cmd.IF_OFFSET1 = xx;
535
536 cmd.SYM_OFFSET0 = xx;
537 cmd.SYM_OFFSET1 = xx;
538 if (enableNtscSweep) {
539 cmd.NTSC_OFFSET0;
540 cmd.NTSC_OFFSET1;
541 }
542 } */
543 bcm3510_do_hab_cmd(st, CMD_ACQUIRE, MSGID_EXT_TUNER_ACQUIRE, (u8 *) &cmd, sizeof(cmd), NULL, 0);
544
545/* doing it with different MSGIDs, data book and source differs */
546 bert.BE = 0;
547 bert.unused = 0;
548 bcm3510_do_hab_cmd(st, CMD_STATE_CONTROL, MSGID_BERT_CONTROL, (u8 *) &bert, sizeof(bert), NULL, 0);
549 bcm3510_do_hab_cmd(st, CMD_STATE_CONTROL, MSGID_BERT_SET, (u8 *) &bert, sizeof(bert), NULL, 0);
550
551 bcm3510_bert_reset(st);
552
553 if ((ret = bcm3510_set_freq(st,p->frequency)) < 0)
554 return ret;
555
556 memset(&st->status1,0,sizeof(st->status1));
557 memset(&st->status2,0,sizeof(st->status2));
558 st->status_check_interval = 500;
559
560/* Give the AP some time */
561 msleep(200);
562
563 return 0;
564}
565
566static int bcm3510_sleep(struct dvb_frontend* fe)
567{
568 return 0;
569}
570
571static int bcm3510_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *s)
572{
573 s->min_delay_ms = 1000;
574 s->step_size = 0;
575 s->max_drift = 0;
576 return 0;
577}
578
579static void bcm3510_release(struct dvb_frontend* fe)
580{
581 struct bcm3510_state* state = fe->demodulator_priv;
582 kfree(state);
583}
584
585/* firmware download:
586 * firmware file is build up like this:
587 * 16bit addr, 16bit length, 8byte of length
588 */
589#define BCM3510_DEFAULT_FIRMWARE "dvb-fe-bcm3510-01.fw"
590
591static int bcm3510_write_ram(struct bcm3510_state *st, u16 addr, u8 *b, u16 len)
592{
593 int ret = 0,i;
594 bcm3510_register_value vH, vL,vD;
595
596 vH.MADRH_a9 = addr >> 8;
597 vL.MADRL_aa = addr;
598 if ((ret = bcm3510_writeB(st,0xa9,vH)) < 0) return ret;
599 if ((ret = bcm3510_writeB(st,0xaa,vL)) < 0) return ret;
600
601 for (i = 0; i < len; i++) {
602 vD.MDATA_ab = b[i];
603 if ((ret = bcm3510_writeB(st,0xab,vD)) < 0)
604 return ret;
605 }
606
607 return 0;
608}
609
610static int bcm3510_download_firmware(struct dvb_frontend* fe)
611{
612 struct bcm3510_state* st = fe->demodulator_priv;
613 const struct firmware *fw;
614 u16 addr,len;
615 u8 *b;
616 int ret,i;
617
618 deb_info("requesting firmware\n");
619 if ((ret = st->config->request_firmware(fe, &fw, BCM3510_DEFAULT_FIRMWARE)) < 0) {
620 err("could not load firmware (%s): %d",BCM3510_DEFAULT_FIRMWARE,ret);
621 return ret;
622 }
623 deb_info("got firmware: %d\n",fw->size);
624
625 b = fw->data;
626 for (i = 0; i < fw->size;) {
627 addr = le16_to_cpu( *( (u16 *)&b[i] ) );
628 len = le16_to_cpu( *( (u16 *)&b[i+2] ) );
629 deb_info("firmware chunk, addr: 0x%04x, len: 0x%04x, total length: 0x%04x\n",addr,len,fw->size);
630 if ((ret = bcm3510_write_ram(st,addr,&b[i+4],len)) < 0) {
631 err("firmware download failed: %d\n",ret);
632 return ret;
633 }
634 i += 4 + len;
635 }
636 release_firmware(fw);
637 deb_info("firmware download successfully completed\n");
638 return 0;
639}
640
641static int bcm3510_check_firmware_version(struct bcm3510_state *st)
642{
643 struct bcm3510_hab_cmd_get_version_info ver;
644 bcm3510_do_hab_cmd(st,CMD_GET_VERSION_INFO,MSGID_GET_VERSION_INFO,NULL,0,(u8*)&ver,sizeof(ver));
645
646 deb_info("Version information: 0x%02x 0x%02x 0x%02x 0x%02x\n",
647 ver.microcode_version, ver.script_version, ver.config_version, ver.demod_version);
648
649 if (ver.script_version == BCM3510_DEF_SCRIPT_VERSION &&
650 ver.config_version == BCM3510_DEF_CONFIG_VERSION &&
651 ver.demod_version == BCM3510_DEF_DEMOD_VERSION)
652 return 0;
653
654 deb_info("version check failed\n");
655 return -ENODEV;
656}
657
658/* (un)resetting the AP */
659static int bcm3510_reset(struct bcm3510_state *st)
660{
661 int ret;
662 unsigned long t;
663 bcm3510_register_value v;
664
665 bcm3510_readB(st,0xa0,&v); v.HCTL1_a0.RESET = 1;
666 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0)
667 return ret;
668
669 t = jiffies + 3*HZ;
670 while (time_before(jiffies, t)) {
671 msleep(10);
672 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
673 return ret;
674
675 if (v.APSTAT1_a2.RESET)
676 return 0;
677 }
678 deb_info("reset timed out\n");
679 return -ETIMEDOUT;
680}
681
682static int bcm3510_clear_reset(struct bcm3510_state *st)
683{
684 bcm3510_register_value v;
685 int ret;
686 unsigned long t;
687
688 v.raw = 0;
689 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0)
690 return ret;
691
692 t = jiffies + 3*HZ;
693 while (time_before(jiffies, t)) {
694 msleep(10);
695 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
696 return ret;
697
698 /* verify that reset is cleared */
699 if (!v.APSTAT1_a2.RESET)
700 return 0;
701 }
702 deb_info("reset clear timed out\n");
703 return -ETIMEDOUT;
704}
705
706static int bcm3510_init_cold(struct bcm3510_state *st)
707{
708 int ret;
709 bcm3510_register_value v;
710
711 /* read Acquisation Processor status register and check it is not in RUN mode */
712 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
713 return ret;
714 if (v.APSTAT1_a2.RUN) {
715 deb_info("AP is already running - firmware already loaded.\n");
716 return 0;
717 }
718
719 deb_info("reset?\n");
720 if ((ret = bcm3510_reset(st)) < 0)
721 return ret;
722
723 deb_info("tristate?\n");
724 /* tri-state */
725 v.TSTCTL_2e.CTL = 0;
726 if ((ret = bcm3510_writeB(st,0x2e,v)) < 0)
727 return ret;
728
729 deb_info("firmware?\n");
730 if ((ret = bcm3510_download_firmware(&st->frontend)) < 0 ||
731 (ret = bcm3510_clear_reset(st)) < 0)
732 return ret;
733
734 /* anything left here to Let the acquisition processor begin execution at program counter 0000 ??? */
735
736 return 0;
737}
738
739static int bcm3510_init(struct dvb_frontend* fe)
740{
741 struct bcm3510_state* st = fe->demodulator_priv;
742 bcm3510_register_value j;
743 struct bcm3510_hab_cmd_set_agc c;
744 int ret;
745
746 if ((ret = bcm3510_readB(st,0xca,&j)) < 0)
747 return ret;
748
749 deb_info("JDEC: %02x\n",j.raw);
750
751 switch (j.JDEC_ca.JDEC) {
752 case JDEC_WAIT_AT_RAM:
753 deb_info("attempting to download firmware\n");
754 if ((ret = bcm3510_init_cold(st)) < 0)
755 return ret;
756 case JDEC_EEPROM_LOAD_WAIT: /* fall-through is wanted */
757 deb_info("firmware is loaded\n");
758 bcm3510_check_firmware_version(st);
759 break;
760 default:
761 return -ENODEV;
762 }
763
764 memset(&c,0,1);
765 c.SEL = 1;
766 bcm3510_do_hab_cmd(st,CMD_AUTO_PARAM,MSGID_SET_RF_AGC_SEL,(u8 *)&c,sizeof(c),NULL,0);
767
768 return 0;
769}
770
771
772static struct dvb_frontend_ops bcm3510_ops;
773
774struct dvb_frontend* bcm3510_attach(const struct bcm3510_config *config,
775 struct i2c_adapter *i2c)
776{
777 struct bcm3510_state* state = NULL;
778 int ret;
779 bcm3510_register_value v;
780
781 /* allocate memory for the internal state */
782 state = kmalloc(sizeof(struct bcm3510_state), GFP_KERNEL);
783 if (state == NULL)
784 goto error;
785 memset(state,0,sizeof(struct bcm3510_state));
786
787 /* setup the state */
788
789 state->config = config;
790 state->i2c = i2c;
791 memcpy(&state->ops, &bcm3510_ops, sizeof(struct dvb_frontend_ops));
792
793 /* create dvb_frontend */
794 state->frontend.ops = &state->ops;
795 state->frontend.demodulator_priv = state;
796
797 sema_init(&state->hab_sem, 1);
798
799 if ((ret = bcm3510_readB(state,0xe0,&v)) < 0)
800 goto error;
801
802 deb_info("Revision: 0x%1x, Layer: 0x%1x.\n",v.REVID_e0.REV,v.REVID_e0.LAYER);
803
804 if ((v.REVID_e0.REV != 0x1 && v.REVID_e0.LAYER != 0xb) && /* cold */
805 (v.REVID_e0.REV != 0x8 && v.REVID_e0.LAYER != 0x0)) /* warm */
806 goto error;
807
808 info("Revision: 0x%1x, Layer: 0x%1x.",v.REVID_e0.REV,v.REVID_e0.LAYER);
809
810 bcm3510_reset(state);
811
812 return &state->frontend;
813
814error:
815 kfree(state);
816 return NULL;
817}
818EXPORT_SYMBOL(bcm3510_attach);
819
820static struct dvb_frontend_ops bcm3510_ops = {
821
822 .info = {
823 .name = "Broadcom BCM3510 VSB/QAM frontend",
824 .type = FE_ATSC,
825 .frequency_min = 54000000,
826 .frequency_max = 803000000,
827 /* stepsize is just a guess */
828 .frequency_stepsize = 0,
829 .caps =
830 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
831 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
832 FE_CAN_8VSB | FE_CAN_16VSB |
833 FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_128 | FE_CAN_QAM_256
834 },
835
836 .release = bcm3510_release,
837
838 .init = bcm3510_init,
839 .sleep = bcm3510_sleep,
840
841 .set_frontend = bcm3510_set_frontend,
842 .get_tune_settings = bcm3510_get_tune_settings,
843
844 .read_status = bcm3510_read_status,
845 .read_ber = bcm3510_read_ber,
846 .read_signal_strength = bcm3510_read_signal_strength,
847 .read_snr = bcm3510_read_snr,
848 .read_ucblocks = bcm3510_read_unc,
849};
850
851MODULE_DESCRIPTION("Broadcom BCM3510 ATSC (8VSB/16VSB & ITU J83 AnnexB FEC QAM64/256) demodulator driver");
852MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
853MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/bcm3510.h b/drivers/media/dvb/frontends/bcm3510.h
new file mode 100644
index 000000000000..80f5d0953d02
--- /dev/null
+++ b/drivers/media/dvb/frontends/bcm3510.h
@@ -0,0 +1,40 @@
1/*
2 * Support for the Broadcom BCM3510 ATSC demodulator (1st generation Air2PC)
3 *
4 * Copyright (C) 2001-5, B2C2 inc.
5 *
6 * GPL/Linux driver written by Patrick Boettcher <patrick.boettcher@desy.de>
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#ifndef BCM3510_H
23#define BCM3510_H
24
25#include <linux/dvb/frontend.h>
26#include <linux/firmware.h>
27
28struct bcm3510_config
29{
30 /* the demodulator's i2c address */
31 u8 demod_address;
32
33 /* request firmware for device */
34 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
35};
36
37extern struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config,
38 struct i2c_adapter* i2c);
39
40#endif
diff --git a/drivers/media/dvb/frontends/bcm3510_priv.h b/drivers/media/dvb/frontends/bcm3510_priv.h
new file mode 100644
index 000000000000..3bb1bc2a04f0
--- /dev/null
+++ b/drivers/media/dvb/frontends/bcm3510_priv.h
@@ -0,0 +1,460 @@
1/*
2 * Support for the Broadcom BCM3510 ATSC demodulator (1st generation Air2PC)
3 *
4 * Copyright (C) 2001-5, B2C2 inc.
5 *
6 * GPL/Linux driver written by Patrick Boettcher <patrick.boettcher@desy.de>
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#ifndef __BCM3510_PRIV_H__
23#define __BCM3510_PRIV_H__
24
25#define PACKED __attribute__((packed))
26
27#undef err
28#define err(format, arg...) printk(KERN_ERR "bcm3510: " format "\n" , ## arg)
29#undef info
30#define info(format, arg...) printk(KERN_INFO "bcm3510: " format "\n" , ## arg)
31#undef warn
32#define warn(format, arg...) printk(KERN_WARNING "bcm3510: " format "\n" , ## arg)
33
34
35#define PANASONIC_FIRST_IF_BASE_IN_KHz 1407500
36#define BCM3510_SYMBOL_RATE 5381000
37
38typedef union {
39 u8 raw;
40
41 struct {
42 u8 CTL :8;
43 } TSTCTL_2e;
44
45 u8 LDCERC_4e;
46 u8 LDUERC_4f;
47 u8 LD_BER0_65;
48 u8 LD_BER1_66;
49 u8 LD_BER2_67;
50 u8 LD_BER3_68;
51
52 struct {
53 u8 RESET :1;
54 u8 IDLE :1;
55 u8 STOP :1;
56 u8 HIRQ0 :1;
57 u8 HIRQ1 :1;
58 u8 na0 :1;
59 u8 HABAV :1;
60 u8 na1 :1;
61 } HCTL1_a0;
62
63 struct {
64 u8 na0 :1;
65 u8 IDLMSK :1;
66 u8 STMSK :1;
67 u8 I0MSK :1;
68 u8 I1MSK :1;
69 u8 na1 :1;
70 u8 HABMSK :1;
71 u8 na2 :1;
72 } HCTLMSK_a1;
73
74 struct {
75 u8 RESET :1;
76 u8 IDLE :1;
77 u8 STOP :1;
78 u8 RUN :1;
79 u8 HABAV :1;
80 u8 MEMAV :1;
81 u8 ALDONE :1;
82 u8 REIRQ :1;
83 } APSTAT1_a2;
84
85 struct {
86 u8 RSTMSK :1;
87 u8 IMSK :1;
88 u8 SMSK :1;
89 u8 RMSK :1;
90 u8 HABMSK :1;
91 u8 MAVMSK :1;
92 u8 ALDMSK :1;
93 u8 REMSK :1;
94 } APMSK1_a3;
95
96 u8 APSTAT2_a4;
97 u8 APMSK2_a5;
98
99 struct {
100 u8 HABADR :7;
101 u8 na :1;
102 } HABADR_a6;
103
104 u8 HABDATA_a7;
105
106 struct {
107 u8 HABR :1;
108 u8 LDHABR :1;
109 u8 APMSK :1;
110 u8 HMSK :1;
111 u8 LDMSK :1;
112 u8 na :3;
113 } HABSTAT_a8;
114
115 u8 MADRH_a9;
116 u8 MADRL_aa;
117 u8 MDATA_ab;
118
119 struct {
120#define JDEC_WAIT_AT_RAM 0x7
121#define JDEC_EEPROM_LOAD_WAIT 0x4
122 u8 JDEC :3;
123 u8 na :5;
124 } JDEC_ca;
125
126 struct {
127 u8 REV :4;
128 u8 LAYER :4;
129 } REVID_e0;
130
131 struct {
132 u8 unk0 :1;
133 u8 CNTCTL :1;
134 u8 BITCNT :1;
135 u8 unk1 :1;
136 u8 RESYNC :1;
137 u8 unk2 :3;
138 } BERCTL_fa;
139
140 struct {
141 u8 CSEL0 :1;
142 u8 CLKED0 :1;
143 u8 CSEL1 :1;
144 u8 CLKED1 :1;
145 u8 CLKLEV :1;
146 u8 SPIVAR :1;
147 u8 na :2;
148 } TUNSET_fc;
149
150 struct {
151 u8 CLK :1;
152 u8 DATA :1;
153 u8 CS0 :1;
154 u8 CS1 :1;
155 u8 AGCSEL :1;
156 u8 na0 :1;
157 u8 TUNSEL :1;
158 u8 na1 :1;
159 } TUNCTL_fd;
160
161 u8 TUNSEL0_fe;
162 u8 TUNSEL1_ff;
163
164} bcm3510_register_value;
165
166/* HAB commands */
167
168/* version */
169#define CMD_GET_VERSION_INFO 0x3D
170#define MSGID_GET_VERSION_INFO 0x15
171struct bcm3510_hab_cmd_get_version_info {
172 u8 microcode_version;
173 u8 script_version;
174 u8 config_version;
175 u8 demod_version;
176} PACKED;
177
178#define BCM3510_DEF_MICROCODE_VERSION 0x0E
179#define BCM3510_DEF_SCRIPT_VERSION 0x06
180#define BCM3510_DEF_CONFIG_VERSION 0x01
181#define BCM3510_DEF_DEMOD_VERSION 0xB1
182
183/* acquire */
184#define CMD_ACQUIRE 0x38
185
186#define MSGID_EXT_TUNER_ACQUIRE 0x0A
187struct bcm3510_hab_cmd_ext_acquire {
188 struct {
189 u8 MODE :4;
190 u8 BW :1;
191 u8 FA :1;
192 u8 NTSCSWEEP :1;
193 u8 OFFSET :1;
194 } PACKED ACQUIRE0; /* control_byte */
195
196 struct {
197 u8 IF_FREQ :3;
198 u8 zero0 :1;
199 u8 SYM_RATE :3;
200 u8 zero1 :1;
201 } PACKED ACQUIRE1; /* sym_if */
202
203 u8 IF_OFFSET0; /* IF_Offset_10hz */
204 u8 IF_OFFSET1;
205 u8 SYM_OFFSET0; /* SymbolRateOffset */
206 u8 SYM_OFFSET1;
207 u8 NTSC_OFFSET0; /* NTSC_Offset_10hz */
208 u8 NTSC_OFFSET1;
209} PACKED;
210
211#define MSGID_INT_TUNER_ACQUIRE 0x0B
212struct bcm3510_hab_cmd_int_acquire {
213 struct {
214 u8 MODE :4;
215 u8 BW :1;
216 u8 FA :1;
217 u8 NTSCSWEEP :1;
218 u8 OFFSET :1;
219 } PACKED ACQUIRE0; /* control_byte */
220
221 struct {
222 u8 IF_FREQ :3;
223 u8 zero0 :1;
224 u8 SYM_RATE :3;
225 u8 zero1 :1;
226 } PACKED ACQUIRE1; /* sym_if */
227
228 u8 TUNER_FREQ0;
229 u8 TUNER_FREQ1;
230 u8 TUNER_FREQ2;
231 u8 TUNER_FREQ3;
232 u8 IF_OFFSET0; /* IF_Offset_10hz */
233 u8 IF_OFFSET1;
234 u8 SYM_OFFSET0; /* SymbolRateOffset */
235 u8 SYM_OFFSET1;
236 u8 NTSC_OFFSET0; /* NTSC_Offset_10hz */
237 u8 NTSC_OFFSET1;
238} PACKED;
239
240/* modes */
241#define BCM3510_QAM16 = 0x01
242#define BCM3510_QAM32 = 0x02
243#define BCM3510_QAM64 = 0x03
244#define BCM3510_QAM128 = 0x04
245#define BCM3510_QAM256 = 0x05
246#define BCM3510_8VSB = 0x0B
247#define BCM3510_16VSB = 0x0D
248
249/* IF_FREQS */
250#define BCM3510_IF_TERRESTRIAL 0x0
251#define BCM3510_IF_CABLE 0x1
252#define BCM3510_IF_USE_CMD 0x7
253
254/* SYM_RATE */
255#define BCM3510_SR_8VSB 0x0 /* 5381119 s/sec */
256#define BCM3510_SR_256QAM 0x1 /* 5360537 s/sec */
257#define BCM3510_SR_16QAM 0x2 /* 5056971 s/sec */
258#define BCM3510_SR_MISC 0x3 /* 5000000 s/sec */
259#define BCM3510_SR_USE_CMD 0x7
260
261/* special symbol rate */
262#define CMD_SET_VALUE_NOT_LISTED 0x2d
263#define MSGID_SET_SYMBOL_RATE_NOT_LISTED 0x0c
264struct bcm3510_hab_cmd_set_sr_not_listed {
265 u8 HOST_SYM_RATE0;
266 u8 HOST_SYM_RATE1;
267 u8 HOST_SYM_RATE2;
268 u8 HOST_SYM_RATE3;
269} PACKED;
270
271/* special IF */
272#define MSGID_SET_IF_FREQ_NOT_LISTED 0x0d
273struct bcm3510_hab_cmd_set_if_freq_not_listed {
274 u8 HOST_IF_FREQ0;
275 u8 HOST_IF_FREQ1;
276 u8 HOST_IF_FREQ2;
277 u8 HOST_IF_FREQ3;
278} PACKED;
279
280/* auto reacquire */
281#define CMD_AUTO_PARAM 0x2a
282#define MSGID_AUTO_REACQUIRE 0x0e
283struct bcm3510_hab_cmd_auto_reacquire {
284 u8 ACQ :1; /* on/off*/
285 u8 unused :7;
286} PACKED;
287
288#define MSGID_SET_RF_AGC_SEL 0x12
289struct bcm3510_hab_cmd_set_agc {
290 u8 LVL :1;
291 u8 unused :6;
292 u8 SEL :1;
293} PACKED;
294
295#define MSGID_SET_AUTO_INVERSION 0x14
296struct bcm3510_hab_cmd_auto_inversion {
297 u8 AI :1;
298 u8 unused :7;
299} PACKED;
300
301
302/* bert control */
303#define CMD_STATE_CONTROL 0x12
304#define MSGID_BERT_CONTROL 0x0e
305#define MSGID_BERT_SET 0xfa
306struct bcm3510_hab_cmd_bert_control {
307 u8 BE :1;
308 u8 unused :7;
309} PACKED;
310
311#define MSGID_TRI_STATE 0x2e
312struct bcm3510_hab_cmd_tri_state {
313 u8 RE :1; /* a/d ram port pins */
314 u8 PE :1; /* baud clock pin */
315 u8 AC :1; /* a/d clock pin */
316 u8 BE :1; /* baud clock pin */
317 u8 unused :4;
318} PACKED;
319
320
321/* tune */
322#define CMD_TUNE 0x38
323#define MSGID_TUNE 0x16
324struct bcm3510_hab_cmd_tune_ctrl_data_pair {
325 struct {
326#define BITS_8 0x07
327#define BITS_7 0x06
328#define BITS_6 0x05
329#define BITS_5 0x04
330#define BITS_4 0x03
331#define BITS_3 0x02
332#define BITS_2 0x01
333#define BITS_1 0x00
334 u8 size :3;
335 u8 unk :2;
336 u8 clk_off :1;
337 u8 cs0 :1;
338 u8 cs1 :1;
339
340 } PACKED ctrl;
341
342 u8 data;
343} PACKED;
344
345struct bcm3510_hab_cmd_tune {
346 u8 length;
347 u8 clock_width;
348 u8 misc;
349 u8 TUNCTL_state;
350
351 struct bcm3510_hab_cmd_tune_ctrl_data_pair ctl_dat[16];
352} PACKED;
353
354#define CMD_STATUS 0x38
355#define MSGID_STATUS1 0x08
356struct bcm3510_hab_cmd_status1 {
357 struct {
358 u8 EQ_MODE :4;
359 u8 reserved :2;
360 u8 QRE :1; /* if QSE and the spectrum is inversed */
361 u8 QSE :1; /* automatic spectral inversion */
362 } PACKED STATUS0;
363
364 struct {
365 u8 RECEIVER_LOCK :1;
366 u8 FEC_LOCK :1;
367 u8 OUT_PLL_LOCK :1;
368 u8 reserved :5;
369 } PACKED STATUS1;
370
371 struct {
372 u8 reserved :2;
373 u8 BW :1;
374 u8 NTE :1; /* NTSC filter sweep enabled */
375 u8 AQI :1; /* currently acquiring */
376 u8 FA :1; /* fast acquisition */
377 u8 ARI :1; /* auto reacquire */
378 u8 TI :1; /* programming the tuner */
379 } PACKED STATUS2;
380 u8 STATUS3;
381 u8 SNR_EST0;
382 u8 SNR_EST1;
383 u8 TUNER_FREQ0;
384 u8 TUNER_FREQ1;
385 u8 TUNER_FREQ2;
386 u8 TUNER_FREQ3;
387 u8 SYM_RATE0;
388 u8 SYM_RATE1;
389 u8 SYM_RATE2;
390 u8 SYM_RATE3;
391 u8 SYM_OFFSET0;
392 u8 SYM_OFFSET1;
393 u8 SYM_ERROR0;
394 u8 SYM_ERROR1;
395 u8 IF_FREQ0;
396 u8 IF_FREQ1;
397 u8 IF_FREQ2;
398 u8 IF_FREQ3;
399 u8 IF_OFFSET0;
400 u8 IF_OFFSET1;
401 u8 IF_ERROR0;
402 u8 IF_ERROR1;
403 u8 NTSC_FILTER0;
404 u8 NTSC_FILTER1;
405 u8 NTSC_FILTER2;
406 u8 NTSC_FILTER3;
407 u8 NTSC_OFFSET0;
408 u8 NTSC_OFFSET1;
409 u8 NTSC_ERROR0;
410 u8 NTSC_ERROR1;
411 u8 INT_AGC_LEVEL0;
412 u8 INT_AGC_LEVEL1;
413 u8 EXT_AGC_LEVEL0;
414 u8 EXT_AGC_LEVEL1;
415} PACKED;
416
417#define MSGID_STATUS2 0x14
418struct bcm3510_hab_cmd_status2 {
419 struct {
420 u8 EQ_MODE :4;
421 u8 reserved :2;
422 u8 QRE :1;
423 u8 QSR :1;
424 } PACKED STATUS0;
425 struct {
426 u8 RL :1;
427 u8 FL :1;
428 u8 OL :1;
429 u8 reserved :5;
430 } PACKED STATUS1;
431 u8 SYMBOL_RATE0;
432 u8 SYMBOL_RATE1;
433 u8 SYMBOL_RATE2;
434 u8 SYMBOL_RATE3;
435 u8 LDCERC0;
436 u8 LDCERC1;
437 u8 LDCERC2;
438 u8 LDCERC3;
439 u8 LDUERC0;
440 u8 LDUERC1;
441 u8 LDUERC2;
442 u8 LDUERC3;
443 u8 LDBER0;
444 u8 LDBER1;
445 u8 LDBER2;
446 u8 LDBER3;
447 struct {
448 u8 MODE_TYPE :4; /* acquire mode 0 */
449 u8 reservd :4;
450 } MODE_TYPE;
451 u8 SNR_EST0;
452 u8 SNR_EST1;
453 u8 SIGNAL;
454} PACKED;
455
456#define CMD_SET_RF_BW_NOT_LISTED 0x3f
457#define MSGID_SET_RF_BW_NOT_LISTED 0x11
458/* TODO */
459
460#endif
diff --git a/drivers/media/dvb/frontends/cx22700.c b/drivers/media/dvb/frontends/cx22700.c
index a212279042b8..0c2ed4438618 100644
--- a/drivers/media/dvb/frontends/cx22700.c
+++ b/drivers/media/dvb/frontends/cx22700.c
@@ -232,7 +232,7 @@ static int cx22700_get_tps (struct cx22700_state* state, struct dvb_ofdm_paramet
232 232
233static int cx22700_init (struct dvb_frontend* fe) 233static int cx22700_init (struct dvb_frontend* fe)
234 234
235{ struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 235{ struct cx22700_state* state = fe->demodulator_priv;
236 int i; 236 int i;
237 237
238 dprintk("cx22700_init: init chip\n"); 238 dprintk("cx22700_init: init chip\n");
@@ -258,7 +258,7 @@ static int cx22700_init (struct dvb_frontend* fe)
258 258
259static int cx22700_read_status(struct dvb_frontend* fe, fe_status_t* status) 259static int cx22700_read_status(struct dvb_frontend* fe, fe_status_t* status)
260{ 260{
261 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 261 struct cx22700_state* state = fe->demodulator_priv;
262 262
263 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9) 263 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9)
264 | (cx22700_readreg (state, 0x0e) << 1); 264 | (cx22700_readreg (state, 0x0e) << 1);
@@ -286,7 +286,7 @@ static int cx22700_read_status(struct dvb_frontend* fe, fe_status_t* status)
286 286
287static int cx22700_read_ber(struct dvb_frontend* fe, u32* ber) 287static int cx22700_read_ber(struct dvb_frontend* fe, u32* ber)
288{ 288{
289 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 289 struct cx22700_state* state = fe->demodulator_priv;
290 290
291 *ber = cx22700_readreg (state, 0x0c) & 0x7f; 291 *ber = cx22700_readreg (state, 0x0c) & 0x7f;
292 cx22700_writereg (state, 0x0c, 0x00); 292 cx22700_writereg (state, 0x0c, 0x00);
@@ -296,7 +296,7 @@ static int cx22700_read_ber(struct dvb_frontend* fe, u32* ber)
296 296
297static int cx22700_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) 297static int cx22700_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
298{ 298{
299 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 299 struct cx22700_state* state = fe->demodulator_priv;
300 300
301 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9) 301 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9)
302 | (cx22700_readreg (state, 0x0e) << 1); 302 | (cx22700_readreg (state, 0x0e) << 1);
@@ -307,7 +307,7 @@ static int cx22700_read_signal_strength(struct dvb_frontend* fe, u16* signal_str
307 307
308static int cx22700_read_snr(struct dvb_frontend* fe, u16* snr) 308static int cx22700_read_snr(struct dvb_frontend* fe, u16* snr)
309{ 309{
310 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 310 struct cx22700_state* state = fe->demodulator_priv;
311 311
312 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9) 312 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9)
313 | (cx22700_readreg (state, 0x0e) << 1); 313 | (cx22700_readreg (state, 0x0e) << 1);
@@ -318,7 +318,7 @@ static int cx22700_read_snr(struct dvb_frontend* fe, u16* snr)
318 318
319static int cx22700_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 319static int cx22700_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
320{ 320{
321 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 321 struct cx22700_state* state = fe->demodulator_priv;
322 322
323 *ucblocks = cx22700_readreg (state, 0x0f); 323 *ucblocks = cx22700_readreg (state, 0x0f);
324 cx22700_writereg (state, 0x0f, 0x00); 324 cx22700_writereg (state, 0x0f, 0x00);
@@ -328,7 +328,7 @@ static int cx22700_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
328 328
329static int cx22700_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 329static int cx22700_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
330{ 330{
331 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 331 struct cx22700_state* state = fe->demodulator_priv;
332 332
333 cx22700_writereg (state, 0x00, 0x02); /* XXX CHECKME: soft reset*/ 333 cx22700_writereg (state, 0x00, 0x02); /* XXX CHECKME: soft reset*/
334 cx22700_writereg (state, 0x00, 0x00); 334 cx22700_writereg (state, 0x00, 0x00);
@@ -346,7 +346,7 @@ static int cx22700_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
346 346
347static int cx22700_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 347static int cx22700_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
348{ 348{
349 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 349 struct cx22700_state* state = fe->demodulator_priv;
350 u8 reg09 = cx22700_readreg (state, 0x09); 350 u8 reg09 = cx22700_readreg (state, 0x09);
351 351
352 p->inversion = reg09 & 0x1 ? INVERSION_ON : INVERSION_OFF; 352 p->inversion = reg09 & 0x1 ? INVERSION_ON : INVERSION_OFF;
@@ -363,7 +363,7 @@ static int cx22700_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronten
363 363
364static void cx22700_release(struct dvb_frontend* fe) 364static void cx22700_release(struct dvb_frontend* fe)
365{ 365{
366 struct cx22700_state* state = (struct cx22700_state*) fe->demodulator_priv; 366 struct cx22700_state* state = fe->demodulator_priv;
367 kfree(state); 367 kfree(state);
368} 368}
369 369
@@ -375,7 +375,7 @@ struct dvb_frontend* cx22700_attach(const struct cx22700_config* config,
375 struct cx22700_state* state = NULL; 375 struct cx22700_state* state = NULL;
376 376
377 /* allocate memory for the internal state */ 377 /* allocate memory for the internal state */
378 state = (struct cx22700_state*) kmalloc(sizeof(struct cx22700_state), GFP_KERNEL); 378 state = kmalloc(sizeof(struct cx22700_state), GFP_KERNEL);
379 if (state == NULL) goto error; 379 if (state == NULL) goto error;
380 380
381 /* setup the state */ 381 /* setup the state */
diff --git a/drivers/media/dvb/frontends/cx22702.c b/drivers/media/dvb/frontends/cx22702.c
index 011860ce36cc..f4aa44136c7c 100644
--- a/drivers/media/dvb/frontends/cx22702.c
+++ b/drivers/media/dvb/frontends/cx22702.c
@@ -200,7 +200,7 @@ static int cx22702_get_tps (struct cx22702_state *state, struct dvb_ofdm_paramet
200static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 200static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
201{ 201{
202 u8 val; 202 u8 val;
203 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 203 struct cx22702_state* state = fe->demodulator_priv;
204 204
205 /* set PLL */ 205 /* set PLL */
206 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) &0xfe); 206 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) &0xfe);
@@ -338,7 +338,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
338static int cx22702_init (struct dvb_frontend* fe) 338static int cx22702_init (struct dvb_frontend* fe)
339{ 339{
340 int i; 340 int i;
341 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 341 struct cx22702_state* state = fe->demodulator_priv;
342 342
343 cx22702_writereg (state, 0x00, 0x02); 343 cx22702_writereg (state, 0x00, 0x02);
344 344
@@ -360,7 +360,7 @@ static int cx22702_init (struct dvb_frontend* fe)
360 360
361static int cx22702_read_status(struct dvb_frontend* fe, fe_status_t* status) 361static int cx22702_read_status(struct dvb_frontend* fe, fe_status_t* status)
362{ 362{
363 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 363 struct cx22702_state* state = fe->demodulator_priv;
364 u8 reg0A; 364 u8 reg0A;
365 u8 reg23; 365 u8 reg23;
366 366
@@ -389,7 +389,7 @@ static int cx22702_read_status(struct dvb_frontend* fe, fe_status_t* status)
389 389
390static int cx22702_read_ber(struct dvb_frontend* fe, u32* ber) 390static int cx22702_read_ber(struct dvb_frontend* fe, u32* ber)
391{ 391{
392 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 392 struct cx22702_state* state = fe->demodulator_priv;
393 393
394 if(cx22702_readreg (state, 0xE4) & 0x02) { 394 if(cx22702_readreg (state, 0xE4) & 0x02) {
395 /* Realtime statistics */ 395 /* Realtime statistics */
@@ -406,7 +406,7 @@ static int cx22702_read_ber(struct dvb_frontend* fe, u32* ber)
406 406
407static int cx22702_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) 407static int cx22702_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
408{ 408{
409 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 409 struct cx22702_state* state = fe->demodulator_priv;
410 410
411 *signal_strength = cx22702_readreg (state, 0x23); 411 *signal_strength = cx22702_readreg (state, 0x23);
412 412
@@ -415,7 +415,7 @@ static int cx22702_read_signal_strength(struct dvb_frontend* fe, u16* signal_str
415 415
416static int cx22702_read_snr(struct dvb_frontend* fe, u16* snr) 416static int cx22702_read_snr(struct dvb_frontend* fe, u16* snr)
417{ 417{
418 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 418 struct cx22702_state* state = fe->demodulator_priv;
419 419
420 u16 rs_ber=0; 420 u16 rs_ber=0;
421 if(cx22702_readreg (state, 0xE4) & 0x02) { 421 if(cx22702_readreg (state, 0xE4) & 0x02) {
@@ -434,7 +434,7 @@ static int cx22702_read_snr(struct dvb_frontend* fe, u16* snr)
434 434
435static int cx22702_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 435static int cx22702_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
436{ 436{
437 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 437 struct cx22702_state* state = fe->demodulator_priv;
438 438
439 u8 _ucblocks; 439 u8 _ucblocks;
440 440
@@ -449,7 +449,7 @@ static int cx22702_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
449 449
450static int cx22702_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 450static int cx22702_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
451{ 451{
452 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 452 struct cx22702_state* state = fe->demodulator_priv;
453 453
454 u8 reg0C = cx22702_readreg (state, 0x0C); 454 u8 reg0C = cx22702_readreg (state, 0x0C);
455 455
@@ -459,7 +459,7 @@ static int cx22702_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
459 459
460static void cx22702_release(struct dvb_frontend* fe) 460static void cx22702_release(struct dvb_frontend* fe)
461{ 461{
462 struct cx22702_state* state = (struct cx22702_state*) fe->demodulator_priv; 462 struct cx22702_state* state = fe->demodulator_priv;
463 kfree(state); 463 kfree(state);
464} 464}
465 465
@@ -471,7 +471,7 @@ struct dvb_frontend* cx22702_attach(const struct cx22702_config* config,
471 struct cx22702_state* state = NULL; 471 struct cx22702_state* state = NULL;
472 472
473 /* allocate memory for the internal state */ 473 /* allocate memory for the internal state */
474 state = (struct cx22702_state*) kmalloc(sizeof(struct cx22702_state), GFP_KERNEL); 474 state = kmalloc(sizeof(struct cx22702_state), GFP_KERNEL);
475 if (state == NULL) goto error; 475 if (state == NULL) goto error;
476 476
477 /* setup the state */ 477 /* setup the state */
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index ae16112a0653..8222b88cb486 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -315,7 +315,7 @@ dprintk("cx24110 debug: entering %s(%d)\n",__FUNCTION__,srate);
315 315
316int cx24110_pll_write (struct dvb_frontend* fe, u32 data) 316int cx24110_pll_write (struct dvb_frontend* fe, u32 data)
317{ 317{
318 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 318 struct cx24110_state *state = fe->demodulator_priv;
319 319
320/* tuner data is 21 bits long, must be left-aligned in data */ 320/* tuner data is 21 bits long, must be left-aligned in data */
321/* tuner cx24108 is written through a dedicated 3wire interface on the demod chip */ 321/* tuner cx24108 is written through a dedicated 3wire interface on the demod chip */
@@ -356,7 +356,7 @@ int cx24110_pll_write (struct dvb_frontend* fe, u32 data)
356 356
357static int cx24110_initfe(struct dvb_frontend* fe) 357static int cx24110_initfe(struct dvb_frontend* fe)
358{ 358{
359 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 359 struct cx24110_state *state = fe->demodulator_priv;
360/* fixme (low): error handling */ 360/* fixme (low): error handling */
361 int i; 361 int i;
362 362
@@ -373,7 +373,7 @@ static int cx24110_initfe(struct dvb_frontend* fe)
373 373
374static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 374static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
375{ 375{
376 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 376 struct cx24110_state *state = fe->demodulator_priv;
377 377
378 switch (voltage) { 378 switch (voltage) {
379 case SEC_VOLTAGE_13: 379 case SEC_VOLTAGE_13:
@@ -385,8 +385,7 @@ static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
385 }; 385 };
386} 386}
387 387
388static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, 388static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
389 fe_sec_mini_cmd_t burst)
390{ 389{
391 int rv, bit, i; 390 int rv, bit, i;
392 struct cx24110_state *state = fe->demodulator_priv; 391 struct cx24110_state *state = fe->demodulator_priv;
@@ -413,7 +412,7 @@ static int cx24110_send_diseqc_msg(struct dvb_frontend* fe,
413 struct dvb_diseqc_master_cmd *cmd) 412 struct dvb_diseqc_master_cmd *cmd)
414{ 413{
415 int i, rv; 414 int i, rv;
416 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 415 struct cx24110_state *state = fe->demodulator_priv;
417 416
418 for (i = 0; i < cmd->msg_len; i++) 417 for (i = 0; i < cmd->msg_len; i++)
419 cx24110_writereg(state, 0x79 + i, cmd->msg[i]); 418 cx24110_writereg(state, 0x79 + i, cmd->msg[i]);
@@ -432,7 +431,7 @@ static int cx24110_send_diseqc_msg(struct dvb_frontend* fe,
432 431
433static int cx24110_read_status(struct dvb_frontend* fe, fe_status_t* status) 432static int cx24110_read_status(struct dvb_frontend* fe, fe_status_t* status)
434{ 433{
435 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 434 struct cx24110_state *state = fe->demodulator_priv;
436 435
437 int sync = cx24110_readreg (state, 0x55); 436 int sync = cx24110_readreg (state, 0x55);
438 437
@@ -460,7 +459,7 @@ static int cx24110_read_status(struct dvb_frontend* fe, fe_status_t* status)
460 459
461static int cx24110_read_ber(struct dvb_frontend* fe, u32* ber) 460static int cx24110_read_ber(struct dvb_frontend* fe, u32* ber)
462{ 461{
463 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 462 struct cx24110_state *state = fe->demodulator_priv;
464 463
465 /* fixme (maybe): value range is 16 bit. Scale? */ 464 /* fixme (maybe): value range is 16 bit. Scale? */
466 if(cx24110_readreg(state,0x24)&0x10) { 465 if(cx24110_readreg(state,0x24)&0x10) {
@@ -478,7 +477,7 @@ static int cx24110_read_ber(struct dvb_frontend* fe, u32* ber)
478 477
479static int cx24110_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) 478static int cx24110_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
480{ 479{
481 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 480 struct cx24110_state *state = fe->demodulator_priv;
482 481
483/* no provision in hardware. Read the frontend AGC accumulator. No idea how to scale this, but I know it is 2s complement */ 482/* no provision in hardware. Read the frontend AGC accumulator. No idea how to scale this, but I know it is 2s complement */
484 u8 signal = cx24110_readreg (state, 0x27)+128; 483 u8 signal = cx24110_readreg (state, 0x27)+128;
@@ -489,7 +488,7 @@ static int cx24110_read_signal_strength(struct dvb_frontend* fe, u16* signal_str
489 488
490static int cx24110_read_snr(struct dvb_frontend* fe, u16* snr) 489static int cx24110_read_snr(struct dvb_frontend* fe, u16* snr)
491{ 490{
492 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 491 struct cx24110_state *state = fe->demodulator_priv;
493 492
494 /* no provision in hardware. Can be computed from the Es/N0 estimator, but I don't know how. */ 493 /* no provision in hardware. Can be computed from the Es/N0 estimator, but I don't know how. */
495 if(cx24110_readreg(state,0x6a)&0x80) { 494 if(cx24110_readreg(state,0x6a)&0x80) {
@@ -505,7 +504,7 @@ static int cx24110_read_snr(struct dvb_frontend* fe, u16* snr)
505 504
506static int cx24110_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 505static int cx24110_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
507{ 506{
508 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 507 struct cx24110_state *state = fe->demodulator_priv;
509 u32 lastbyer; 508 u32 lastbyer;
510 509
511 if(cx24110_readreg(state,0x10)&0x40) { 510 if(cx24110_readreg(state,0x10)&0x40) {
@@ -527,7 +526,7 @@ static int cx24110_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
527 526
528static int cx24110_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 527static int cx24110_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
529{ 528{
530 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 529 struct cx24110_state *state = fe->demodulator_priv;
531 530
532 state->config->pll_set(fe, p); 531 state->config->pll_set(fe, p);
533 cx24110_set_inversion (state, p->inversion); 532 cx24110_set_inversion (state, p->inversion);
@@ -540,7 +539,7 @@ static int cx24110_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
540 539
541static int cx24110_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 540static int cx24110_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
542{ 541{
543 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 542 struct cx24110_state *state = fe->demodulator_priv;
544 s32 afc; unsigned sclk; 543 s32 afc; unsigned sclk;
545 544
546/* cannot read back tuner settings (freq). Need to have some private storage */ 545/* cannot read back tuner settings (freq). Need to have some private storage */
@@ -567,14 +566,14 @@ static int cx24110_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
567 566
568static int cx24110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 567static int cx24110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
569{ 568{
570 struct cx24110_state *state = (struct cx24110_state*) fe->demodulator_priv; 569 struct cx24110_state *state = fe->demodulator_priv;
571 570
572 return cx24110_writereg(state,0x76,(cx24110_readreg(state,0x76)&~0x10)|(((tone==SEC_TONE_ON))?0x10:0)); 571 return cx24110_writereg(state,0x76,(cx24110_readreg(state,0x76)&~0x10)|(((tone==SEC_TONE_ON))?0x10:0));
573} 572}
574 573
575static void cx24110_release(struct dvb_frontend* fe) 574static void cx24110_release(struct dvb_frontend* fe)
576{ 575{
577 struct cx24110_state* state = (struct cx24110_state*) fe->demodulator_priv; 576 struct cx24110_state* state = fe->demodulator_priv;
578 kfree(state); 577 kfree(state);
579} 578}
580 579
@@ -587,7 +586,7 @@ struct dvb_frontend* cx24110_attach(const struct cx24110_config* config,
587 int ret; 586 int ret;
588 587
589 /* allocate memory for the internal state */ 588 /* allocate memory for the internal state */
590 state = (struct cx24110_state*) kmalloc(sizeof(struct cx24110_state), GFP_KERNEL); 589 state = kmalloc(sizeof(struct cx24110_state), GFP_KERNEL);
591 if (state == NULL) goto error; 590 if (state == NULL) goto error;
592 591
593 /* setup the state */ 592 /* setup the state */
diff --git a/drivers/media/dvb/frontends/dib3000-common.c b/drivers/media/dvb/frontends/dib3000-common.c
index 47ab02e133d1..1a4f1f7c228a 100644
--- a/drivers/media/dvb/frontends/dib3000-common.c
+++ b/drivers/media/dvb/frontends/dib3000-common.c
@@ -73,7 +73,7 @@ u16 dib3000_seq[2][2][2] = /* fft,gua, inv */
73 }; 73 };
74 74
75MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de"); 75MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de");
76MODULE_DESCRIPTION("Common functions for the dib3000mb/dib3000mc dvb-frontend drivers"); 76MODULE_DESCRIPTION("Common functions for the dib3000mb/dib3000mc dvb frontend drivers");
77MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
78 78
79EXPORT_SYMBOL(dib3000_seq); 79EXPORT_SYMBOL(dib3000_seq);
diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
index 80687c130836..2d5475b5c063 100644
--- a/drivers/media/dvb/frontends/dib3000.h
+++ b/drivers/media/dvb/frontends/dib3000.h
@@ -32,9 +32,8 @@ struct dib3000_config
32 u8 demod_address; 32 u8 demod_address;
33 33
34 /* PLL maintenance and the i2c address of the PLL */ 34 /* PLL maintenance and the i2c address of the PLL */
35 u8 (*pll_addr)(struct dvb_frontend *fe); 35 int (*pll_init)(struct dvb_frontend *fe);
36 int (*pll_init)(struct dvb_frontend *fe, u8 pll_buf[5]); 36 int (*pll_set)(struct dvb_frontend *fe, struct dvb_frontend_parameters* params);
37 int (*pll_set)(struct dvb_frontend *fe, struct dvb_frontend_parameters* params, u8 pll_buf[5]);
38}; 37};
39 38
40struct dib_fe_xfer_ops 39struct dib_fe_xfer_ops
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index a853d12a26f1..cd434b7cf9db 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -48,23 +48,19 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-a
48#define deb_setf(args...) dprintk(0x04,args) 48#define deb_setf(args...) dprintk(0x04,args)
49#define deb_getf(args...) dprintk(0x08,args) 49#define deb_getf(args...) dprintk(0x08,args)
50 50
51static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr);
52
53static int dib3000mb_get_frontend(struct dvb_frontend* fe, 51static int dib3000mb_get_frontend(struct dvb_frontend* fe,
54 struct dvb_frontend_parameters *fep); 52 struct dvb_frontend_parameters *fep);
55 53
56static int dib3000mb_set_frontend(struct dvb_frontend* fe, 54static int dib3000mb_set_frontend(struct dvb_frontend* fe,
57 struct dvb_frontend_parameters *fep, int tuner) 55 struct dvb_frontend_parameters *fep, int tuner)
58{ 56{
59 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 57 struct dib3000_state* state = fe->demodulator_priv;
60 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm; 58 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
61 fe_code_rate_t fe_cr = FEC_NONE; 59 fe_code_rate_t fe_cr = FEC_NONE;
62 int search_state, seq; 60 int search_state, seq;
63 61
64 if (tuner) { 62 if (tuner && state->config.pll_set) {
65 dib3000mb_tuner_pass_ctrl(fe,1,state->config.pll_addr(fe)); 63 state->config.pll_set(fe, fep);
66 state->config.pll_set(fe, fep, NULL);
67 dib3000mb_tuner_pass_ctrl(fe,0,state->config.pll_addr(fe));
68 64
69 deb_setf("bandwidth: "); 65 deb_setf("bandwidth: ");
70 switch (ofdm->bandwidth) { 66 switch (ofdm->bandwidth) {
@@ -317,7 +313,7 @@ static int dib3000mb_set_frontend(struct dvb_frontend* fe,
317 313
318static int dib3000mb_fe_init(struct dvb_frontend* fe, int mobile_mode) 314static int dib3000mb_fe_init(struct dvb_frontend* fe, int mobile_mode)
319{ 315{
320 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 316 struct dib3000_state* state = fe->demodulator_priv;
321 317
322 deb_info("dib3000mb is getting up.\n"); 318 deb_info("dib3000mb is getting up.\n");
323 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_UP); 319 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_UP);
@@ -389,11 +385,8 @@ static int dib3000mb_fe_init(struct dvb_frontend* fe, int mobile_mode)
389 385
390 wr(DIB3000MB_REG_DATA_IN_DIVERSITY, DIB3000MB_DATA_DIVERSITY_IN_OFF); 386 wr(DIB3000MB_REG_DATA_IN_DIVERSITY, DIB3000MB_DATA_DIVERSITY_IN_OFF);
391 387
392 if (state->config.pll_init) { 388 if (state->config.pll_init)
393 dib3000mb_tuner_pass_ctrl(fe,1,state->config.pll_addr(fe)); 389 state->config.pll_init(fe);
394 state->config.pll_init(fe,NULL);
395 dib3000mb_tuner_pass_ctrl(fe,0,state->config.pll_addr(fe));
396 }
397 390
398 return 0; 391 return 0;
399} 392}
@@ -401,7 +394,7 @@ static int dib3000mb_fe_init(struct dvb_frontend* fe, int mobile_mode)
401static int dib3000mb_get_frontend(struct dvb_frontend* fe, 394static int dib3000mb_get_frontend(struct dvb_frontend* fe,
402 struct dvb_frontend_parameters *fep) 395 struct dvb_frontend_parameters *fep)
403{ 396{
404 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 397 struct dib3000_state* state = fe->demodulator_priv;
405 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm; 398 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
406 fe_code_rate_t *cr; 399 fe_code_rate_t *cr;
407 u16 tps_val; 400 u16 tps_val;
@@ -562,7 +555,7 @@ static int dib3000mb_get_frontend(struct dvb_frontend* fe,
562 555
563static int dib3000mb_read_status(struct dvb_frontend* fe, fe_status_t *stat) 556static int dib3000mb_read_status(struct dvb_frontend* fe, fe_status_t *stat)
564{ 557{
565 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 558 struct dib3000_state* state = fe->demodulator_priv;
566 559
567 *stat = 0; 560 *stat = 0;
568 561
@@ -594,7 +587,7 @@ static int dib3000mb_read_status(struct dvb_frontend* fe, fe_status_t *stat)
594 587
595static int dib3000mb_read_ber(struct dvb_frontend* fe, u32 *ber) 588static int dib3000mb_read_ber(struct dvb_frontend* fe, u32 *ber)
596{ 589{
597 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 590 struct dib3000_state* state = fe->demodulator_priv;
598 591
599 *ber = ((rd(DIB3000MB_REG_BER_MSB) << 16) | rd(DIB3000MB_REG_BER_LSB)); 592 *ber = ((rd(DIB3000MB_REG_BER_MSB) << 16) | rd(DIB3000MB_REG_BER_LSB));
600 return 0; 593 return 0;
@@ -603,7 +596,7 @@ static int dib3000mb_read_ber(struct dvb_frontend* fe, u32 *ber)
603/* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */ 596/* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
604static int dib3000mb_read_signal_strength(struct dvb_frontend* fe, u16 *strength) 597static int dib3000mb_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
605{ 598{
606 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 599 struct dib3000_state* state = fe->demodulator_priv;
607 600
608 *strength = rd(DIB3000MB_REG_SIGNAL_POWER) * 0xffff / 0x170; 601 *strength = rd(DIB3000MB_REG_SIGNAL_POWER) * 0xffff / 0x170;
609 return 0; 602 return 0;
@@ -611,7 +604,7 @@ static int dib3000mb_read_signal_strength(struct dvb_frontend* fe, u16 *strength
611 604
612static int dib3000mb_read_snr(struct dvb_frontend* fe, u16 *snr) 605static int dib3000mb_read_snr(struct dvb_frontend* fe, u16 *snr)
613{ 606{
614 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 607 struct dib3000_state* state = fe->demodulator_priv;
615 short sigpow = rd(DIB3000MB_REG_SIGNAL_POWER); 608 short sigpow = rd(DIB3000MB_REG_SIGNAL_POWER);
616 int icipow = ((rd(DIB3000MB_REG_NOISE_POWER_MSB) & 0xff) << 16) | 609 int icipow = ((rd(DIB3000MB_REG_NOISE_POWER_MSB) & 0xff) << 16) |
617 rd(DIB3000MB_REG_NOISE_POWER_LSB); 610 rd(DIB3000MB_REG_NOISE_POWER_LSB);
@@ -621,15 +614,15 @@ static int dib3000mb_read_snr(struct dvb_frontend* fe, u16 *snr)
621 614
622static int dib3000mb_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) 615static int dib3000mb_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
623{ 616{
624 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 617 struct dib3000_state* state = fe->demodulator_priv;
625 618
626 *unc = rd(DIB3000MB_REG_UNC); 619 *unc = rd(DIB3000MB_REG_PACKET_ERROR_RATE);
627 return 0; 620 return 0;
628} 621}
629 622
630static int dib3000mb_sleep(struct dvb_frontend* fe) 623static int dib3000mb_sleep(struct dvb_frontend* fe)
631{ 624{
632 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 625 struct dib3000_state* state = fe->demodulator_priv;
633 deb_info("dib3000mb is going to bed.\n"); 626 deb_info("dib3000mb is going to bed.\n");
634 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_DOWN); 627 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_DOWN);
635 return 0; 628 return 0;
@@ -638,9 +631,6 @@ static int dib3000mb_sleep(struct dvb_frontend* fe)
638static int dib3000mb_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 631static int dib3000mb_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
639{ 632{
640 tune->min_delay_ms = 800; 633 tune->min_delay_ms = 800;
641 tune->step_size = 166667;
642 tune->max_drift = 166667 * 2;
643
644 return 0; 634 return 0;
645} 635}
646 636
@@ -656,7 +646,7 @@ static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend* fe, struct dvb_
656 646
657static void dib3000mb_release(struct dvb_frontend* fe) 647static void dib3000mb_release(struct dvb_frontend* fe)
658{ 648{
659 struct dib3000_state *state = (struct dib3000_state*) fe->demodulator_priv; 649 struct dib3000_state *state = fe->demodulator_priv;
660 kfree(state); 650 kfree(state);
661} 651}
662 652
@@ -671,7 +661,7 @@ static int dib3000mb_pid_control(struct dvb_frontend *fe,int index, int pid,int
671 661
672static int dib3000mb_fifo_control(struct dvb_frontend *fe, int onoff) 662static int dib3000mb_fifo_control(struct dvb_frontend *fe, int onoff)
673{ 663{
674 struct dib3000_state *state = (struct dib3000_state*) fe->demodulator_priv; 664 struct dib3000_state *state = fe->demodulator_priv;
675 665
676 deb_xfer("%s fifo\n",onoff ? "enabling" : "disabling"); 666 deb_xfer("%s fifo\n",onoff ? "enabling" : "disabling");
677 if (onoff) { 667 if (onoff) {
@@ -692,7 +682,7 @@ static int dib3000mb_pid_parse(struct dvb_frontend *fe, int onoff)
692 682
693static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr) 683static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr)
694{ 684{
695 struct dib3000_state *state = (struct dib3000_state*) fe->demodulator_priv; 685 struct dib3000_state *state = fe->demodulator_priv;
696 if (onoff) { 686 if (onoff) {
697 wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr)); 687 wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr));
698 } else { 688 } else {
@@ -709,7 +699,7 @@ struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
709 struct dib3000_state* state = NULL; 699 struct dib3000_state* state = NULL;
710 700
711 /* allocate memory for the internal state */ 701 /* allocate memory for the internal state */
712 state = (struct dib3000_state*) kmalloc(sizeof(struct dib3000_state), GFP_KERNEL); 702 state = kmalloc(sizeof(struct dib3000_state), GFP_KERNEL);
713 if (state == NULL) 703 if (state == NULL)
714 goto error; 704 goto error;
715 memset(state,0,sizeof(struct dib3000_state)); 705 memset(state,0,sizeof(struct dib3000_state));
diff --git a/drivers/media/dvb/frontends/dib3000mb_priv.h b/drivers/media/dvb/frontends/dib3000mb_priv.h
index 57e61aa5b07b..999b19047816 100644
--- a/drivers/media/dvb/frontends/dib3000mb_priv.h
+++ b/drivers/media/dvb/frontends/dib3000mb_priv.h
@@ -294,7 +294,7 @@ static u16 dib3000mb_reg_filter_coeffs[] = {
294 294
295static u16 dib3000mb_filter_coeffs[] = { 295static u16 dib3000mb_filter_coeffs[] = {
296 226, 160, 29, 296 226, 160, 29,
297 979, 998, 19, 297 979, 998, 19,
298 22, 1019, 1006, 298 22, 1019, 1006,
299 1022, 12, 6, 299 1022, 12, 6,
300 1017, 1017, 3, 300 1017, 1017, 3,
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 4a31c05eaecd..cd33705a4320 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -48,8 +48,6 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe,16=s
48#define deb_getf(args...) dprintk(0x08,args) 48#define deb_getf(args...) dprintk(0x08,args)
49#define deb_stat(args...) dprintk(0x10,args) 49#define deb_stat(args...) dprintk(0x10,args)
50 50
51static int dib3000mc_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr);
52
53static int dib3000mc_set_impulse_noise(struct dib3000_state * state, int mode, 51static int dib3000mc_set_impulse_noise(struct dib3000_state * state, int mode,
54 fe_transmit_mode_t transmission_mode, fe_bandwidth_t bandwidth) 52 fe_transmit_mode_t transmission_mode, fe_bandwidth_t bandwidth)
55{ 53{
@@ -297,7 +295,7 @@ static int dib3000mc_set_general_cfg(struct dib3000_state *state, struct dvb_fro
297static int dib3000mc_get_frontend(struct dvb_frontend* fe, 295static int dib3000mc_get_frontend(struct dvb_frontend* fe,
298 struct dvb_frontend_parameters *fep) 296 struct dvb_frontend_parameters *fep)
299{ 297{
300 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 298 struct dib3000_state* state = fe->demodulator_priv;
301 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm; 299 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
302 fe_code_rate_t *cr; 300 fe_code_rate_t *cr;
303 u16 tps_val,cr_val; 301 u16 tps_val,cr_val;
@@ -458,15 +456,13 @@ static int dib3000mc_get_frontend(struct dvb_frontend* fe,
458static int dib3000mc_set_frontend(struct dvb_frontend* fe, 456static int dib3000mc_set_frontend(struct dvb_frontend* fe,
459 struct dvb_frontend_parameters *fep, int tuner) 457 struct dvb_frontend_parameters *fep, int tuner)
460{ 458{
461 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 459 struct dib3000_state* state = fe->demodulator_priv;
462 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm; 460 struct dvb_ofdm_parameters *ofdm = &fep->u.ofdm;
463 int search_state,auto_val; 461 int search_state,auto_val;
464 u16 val; 462 u16 val;
465 463
466 if (tuner) { /* initial call from dvb */ 464 if (tuner && state->config.pll_set) { /* initial call from dvb */
467 dib3000mc_tuner_pass_ctrl(fe,1,state->config.pll_addr(fe)); 465 state->config.pll_set(fe,fep);
468 state->config.pll_set(fe,fep,NULL);
469 dib3000mc_tuner_pass_ctrl(fe,0,state->config.pll_addr(fe));
470 466
471 state->last_tuned_freq = fep->frequency; 467 state->last_tuned_freq = fep->frequency;
472 // if (!scanboost) { 468 // if (!scanboost) {
@@ -554,19 +550,15 @@ static int dib3000mc_set_frontend(struct dvb_frontend* fe,
554 dib3000mc_set_adp_cfg(state,ofdm->constellation); 550 dib3000mc_set_adp_cfg(state,ofdm->constellation);
555 wr_foreach(dib3000mc_reg_offset, 551 wr_foreach(dib3000mc_reg_offset,
556 dib3000mc_offset[(ofdm->transmission_mode == TRANSMISSION_MODE_8K)+1]); 552 dib3000mc_offset[(ofdm->transmission_mode == TRANSMISSION_MODE_8K)+1]);
557
558
559 } 553 }
560 return 0; 554 return 0;
561} 555}
562 556
563static int dib3000mc_fe_init(struct dvb_frontend* fe, int mobile_mode) 557static int dib3000mc_fe_init(struct dvb_frontend* fe, int mobile_mode)
564{ 558{
565 struct dib3000_state *state; 559 struct dib3000_state *state = fe->demodulator_priv;
566
567 deb_info("init start\n"); 560 deb_info("init start\n");
568 561
569 state = fe->demodulator_priv;
570 state->timing_offset = 0; 562 state->timing_offset = 0;
571 state->timing_offset_comp_done = 0; 563 state->timing_offset_comp_done = 0;
572 564
@@ -649,17 +641,15 @@ static int dib3000mc_fe_init(struct dvb_frontend* fe, int mobile_mode)
649 641
650 set_or(DIB3000MC_REG_CLK_CFG_7,DIB3000MC_CLK_CFG_7_DIV_IN_OFF); 642 set_or(DIB3000MC_REG_CLK_CFG_7,DIB3000MC_CLK_CFG_7_DIV_IN_OFF);
651 643
652/* if (state->config->pll_init) { 644 if (state->config.pll_init)
653 dib3000mc_tuner_pass_ctrl(fe,1,state->config.pll_addr(fe)); 645 state->config.pll_init(fe);
654 state->config->pll_init(fe,NULL); 646
655 dib3000mc_tuner_pass_ctrl(fe,0,state->config.pll_addr(fe));
656 }*/
657 deb_info("init end\n"); 647 deb_info("init end\n");
658 return 0; 648 return 0;
659} 649}
660static int dib3000mc_read_status(struct dvb_frontend* fe, fe_status_t *stat) 650static int dib3000mc_read_status(struct dvb_frontend* fe, fe_status_t *stat)
661{ 651{
662 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 652 struct dib3000_state* state = fe->demodulator_priv;
663 u16 lock = rd(DIB3000MC_REG_LOCKING); 653 u16 lock = rd(DIB3000MC_REG_LOCKING);
664 654
665 *stat = 0; 655 *stat = 0;
@@ -679,23 +669,23 @@ static int dib3000mc_read_status(struct dvb_frontend* fe, fe_status_t *stat)
679 669
680static int dib3000mc_read_ber(struct dvb_frontend* fe, u32 *ber) 670static int dib3000mc_read_ber(struct dvb_frontend* fe, u32 *ber)
681{ 671{
682 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 672 struct dib3000_state* state = fe->demodulator_priv;
683 *ber = ((rd(DIB3000MC_REG_BER_MSB) << 16) | rd(DIB3000MC_REG_BER_LSB)); 673 *ber = ((rd(DIB3000MC_REG_BER_MSB) << 16) | rd(DIB3000MC_REG_BER_LSB));
684 return 0; 674 return 0;
685} 675}
686 676
687static int dib3000mc_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) 677static int dib3000mc_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
688{ 678{
689 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 679 struct dib3000_state* state = fe->demodulator_priv;
690 680
691 *unc = rd(DIB3000MC_REG_PACKET_ERROR_COUNT); 681 *unc = rd(DIB3000MC_REG_PACKET_ERRORS);
692 return 0; 682 return 0;
693} 683}
694 684
695/* see dib3000mb.c for calculation comments */ 685/* see dib3000mb.c for calculation comments */
696static int dib3000mc_read_signal_strength(struct dvb_frontend* fe, u16 *strength) 686static int dib3000mc_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
697{ 687{
698 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 688 struct dib3000_state* state = fe->demodulator_priv;
699 u16 val = rd(DIB3000MC_REG_SIGNAL_NOISE_LSB); 689 u16 val = rd(DIB3000MC_REG_SIGNAL_NOISE_LSB);
700 *strength = (((val >> 6) & 0xff) << 8) + (val & 0x3f); 690 *strength = (((val >> 6) & 0xff) << 8) + (val & 0x3f);
701 691
@@ -706,7 +696,7 @@ static int dib3000mc_read_signal_strength(struct dvb_frontend* fe, u16 *strength
706/* see dib3000mb.c for calculation comments */ 696/* see dib3000mb.c for calculation comments */
707static int dib3000mc_read_snr(struct dvb_frontend* fe, u16 *snr) 697static int dib3000mc_read_snr(struct dvb_frontend* fe, u16 *snr)
708{ 698{
709 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 699 struct dib3000_state* state = fe->demodulator_priv;
710 u16 val = rd(DIB3000MC_REG_SIGNAL_NOISE_LSB), 700 u16 val = rd(DIB3000MC_REG_SIGNAL_NOISE_LSB),
711 val2 = rd(DIB3000MC_REG_SIGNAL_NOISE_MSB); 701 val2 = rd(DIB3000MC_REG_SIGNAL_NOISE_MSB);
712 u16 sig,noise; 702 u16 sig,noise;
@@ -726,7 +716,7 @@ static int dib3000mc_read_snr(struct dvb_frontend* fe, u16 *snr)
726 716
727static int dib3000mc_sleep(struct dvb_frontend* fe) 717static int dib3000mc_sleep(struct dvb_frontend* fe)
728{ 718{
729 struct dib3000_state* state = (struct dib3000_state*) fe->demodulator_priv; 719 struct dib3000_state* state = fe->demodulator_priv;
730 720
731 set_or(DIB3000MC_REG_CLK_CFG_7,DIB3000MC_CLK_CFG_7_PWR_DOWN); 721 set_or(DIB3000MC_REG_CLK_CFG_7,DIB3000MC_CLK_CFG_7_PWR_DOWN);
732 wr(DIB3000MC_REG_CLK_CFG_1,DIB3000MC_CLK_CFG_1_POWER_DOWN); 722 wr(DIB3000MC_REG_CLK_CFG_1,DIB3000MC_CLK_CFG_1_POWER_DOWN);
@@ -737,10 +727,7 @@ static int dib3000mc_sleep(struct dvb_frontend* fe)
737 727
738static int dib3000mc_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 728static int dib3000mc_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
739{ 729{
740 tune->min_delay_ms = 2000; 730 tune->min_delay_ms = 1000;
741 tune->step_size = 166667;
742 tune->max_drift = 166667 * 2;
743
744 return 0; 731 return 0;
745} 732}
746 733
@@ -756,7 +743,7 @@ static int dib3000mc_set_frontend_and_tuner(struct dvb_frontend* fe, struct dvb_
756 743
757static void dib3000mc_release(struct dvb_frontend* fe) 744static void dib3000mc_release(struct dvb_frontend* fe)
758{ 745{
759 struct dib3000_state *state = (struct dib3000_state *) fe->demodulator_priv; 746 struct dib3000_state *state = fe->demodulator_priv;
760 kfree(state); 747 kfree(state);
761} 748}
762 749
@@ -771,7 +758,7 @@ static int dib3000mc_pid_control(struct dvb_frontend *fe,int index, int pid,int
771 758
772static int dib3000mc_fifo_control(struct dvb_frontend *fe, int onoff) 759static int dib3000mc_fifo_control(struct dvb_frontend *fe, int onoff)
773{ 760{
774 struct dib3000_state *state = (struct dib3000_state*) fe->demodulator_priv; 761 struct dib3000_state *state = fe->demodulator_priv;
775 u16 tmp = rd(DIB3000MC_REG_SMO_MODE); 762 u16 tmp = rd(DIB3000MC_REG_SMO_MODE);
776 763
777 deb_xfer("%s fifo\n",onoff ? "enabling" : "disabling"); 764 deb_xfer("%s fifo\n",onoff ? "enabling" : "disabling");
@@ -803,7 +790,7 @@ static int dib3000mc_pid_parse(struct dvb_frontend *fe, int onoff)
803 790
804static int dib3000mc_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr) 791static int dib3000mc_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr)
805{ 792{
806 struct dib3000_state *state = (struct dib3000_state*) fe->demodulator_priv; 793 struct dib3000_state *state = fe->demodulator_priv;
807 if (onoff) { 794 if (onoff) {
808 wr(DIB3000MC_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr)); 795 wr(DIB3000MC_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr));
809 } else { 796 } else {
@@ -844,7 +831,7 @@ struct dvb_frontend* dib3000mc_attach(const struct dib3000_config* config,
844 u16 devid; 831 u16 devid;
845 832
846 /* allocate memory for the internal state */ 833 /* allocate memory for the internal state */
847 state = (struct dib3000_state*) kmalloc(sizeof(struct dib3000_state), GFP_KERNEL); 834 state = kmalloc(sizeof(struct dib3000_state), GFP_KERNEL);
848 if (state == NULL) 835 if (state == NULL)
849 goto error; 836 goto error;
850 memset(state,0,sizeof(struct dib3000_state)); 837 memset(state,0,sizeof(struct dib3000_state));
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index 2a3c2ce7b2aa..f73b5f48e235 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: dvb-pll.c,v 1.7 2005/02/10 11:52:02 kraxel Exp $
3 *
4 * descriptions + helper functions for simple dvb plls. 2 * descriptions + helper functions for simple dvb plls.
5 * 3 *
6 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
@@ -114,6 +112,92 @@ struct dvb_pll_desc dvb_pll_unknown_1 = {
114}; 112};
115EXPORT_SYMBOL(dvb_pll_unknown_1); 113EXPORT_SYMBOL(dvb_pll_unknown_1);
116 114
115/* Infineon TUA6010XS
116 * used in Thomson Cable Tuner
117 */
118struct dvb_pll_desc dvb_pll_tua6010xs = {
119 .name = "Infineon TUA6010XS",
120 .min = 44250000,
121 .max = 858000000,
122 .count = 3,
123 .entries = {
124 { 115750000, 36125000, 62500, 0x8e, 0x03 },
125 { 403250000, 36125000, 62500, 0x8e, 0x06 },
126 { 999999999, 36125000, 62500, 0x8e, 0x85 },
127 },
128};
129EXPORT_SYMBOL(dvb_pll_tua6010xs);
130
131/* Panasonic env57h1xd5 (some Philips PLL ?) */
132struct dvb_pll_desc dvb_pll_env57h1xd5 = {
133 .name = "Panasonic ENV57H1XD5",
134 .min = 44250000,
135 .max = 858000000,
136 .count = 4,
137 .entries = {
138 { 153000000, 36291666, 166666, 0xc2, 0x41 },
139 { 470000000, 36291666, 166666, 0xc2, 0x42 },
140 { 526000000, 36291666, 166666, 0xc2, 0x84 },
141 { 999999999, 36291666, 166666, 0xc2, 0xa4 },
142 },
143};
144EXPORT_SYMBOL(dvb_pll_env57h1xd5);
145
146/* Philips TDA6650/TDA6651
147 * used in Panasonic ENV77H11D5
148 */
149static void tda665x_bw(u8 *buf, int bandwidth)
150{
151 if (bandwidth == BANDWIDTH_8_MHZ)
152 buf[3] |= 0x08;
153}
154
155struct dvb_pll_desc dvb_pll_tda665x = {
156 .name = "Philips TDA6650/TDA6651",
157 .min = 44250000,
158 .max = 858000000,
159 .setbw = tda665x_bw,
160 .count = 12,
161 .entries = {
162 { 93834000, 36249333, 166667, 0xca, 0x61 /* 011 0 0 0 01 */ },
163 { 123834000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
164 { 161000000, 36249333, 166667, 0xca, 0xa1 /* 101 0 0 0 01 */ },
165 { 163834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
166 { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
167 { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
168 { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
169 { 444000000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
170 { 583834000, 36249333, 166667, 0xca, 0x63 /* 011 0 0 0 11 */ },
171 { 793834000, 36249333, 166667, 0xca, 0xa3 /* 101 0 0 0 11 */ },
172 { 444834000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ },
173 { 861000000, 36249333, 166667, 0xca, 0xe3 /* 111 0 0 0 11 */ },
174 }
175};
176EXPORT_SYMBOL(dvb_pll_tda665x);
177
178/* Infineon TUA6034
179 * used in LG TDTP E102P
180 */
181static void tua6034_bw(u8 *buf, int bandwidth)
182{
183 if (BANDWIDTH_7_MHZ != bandwidth)
184 buf[3] |= 0x08;
185}
186
187struct dvb_pll_desc dvb_pll_tua6034 = {
188 .name = "Infineon TUA6034",
189 .min = 44250000,
190 .max = 858000000,
191 .count = 3,
192 .setbw = tua6034_bw,
193 .entries = {
194 { 174500000, 36166667, 62500, 0xce, 0x01 },
195 { 230000000, 36166667, 62500, 0xce, 0x02 },
196 { 999999999, 36166667, 62500, 0xce, 0x04 },
197 },
198};
199EXPORT_SYMBOL(dvb_pll_tua6034);
200
117/* ----------------------------------------------------------- */ 201/* ----------------------------------------------------------- */
118/* code */ 202/* code */
119 203
@@ -160,9 +244,3 @@ EXPORT_SYMBOL(dvb_pll_configure);
160MODULE_DESCRIPTION("dvb pll library"); 244MODULE_DESCRIPTION("dvb pll library");
161MODULE_AUTHOR("Gerd Knorr"); 245MODULE_AUTHOR("Gerd Knorr");
162MODULE_LICENSE("GPL"); 246MODULE_LICENSE("GPL");
163
164/*
165 * Local variables:
166 * c-basic-offset: 8
167 * End:
168 */
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index 016c794a5677..b796778624b6 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -1,7 +1,10 @@
1/* 1/*
2 * $Id: dvb-pll.h,v 1.2 2005/02/10 11:43:41 kraxel Exp $ 2 * descriptions + helper functions for simple dvb plls.
3 */ 3 */
4 4
5#ifndef __DVB_PLL_H__
6#define __DVB_PLL_H__
7
5struct dvb_pll_desc { 8struct dvb_pll_desc {
6 char *name; 9 char *name;
7 u32 min; 10 u32 min;
@@ -14,7 +17,7 @@ struct dvb_pll_desc {
14 u32 stepsize; 17 u32 stepsize;
15 u8 cb1; 18 u8 cb1;
16 u8 cb2; 19 u8 cb2;
17 } entries[9]; 20 } entries[12];
18}; 21};
19 22
20extern struct dvb_pll_desc dvb_pll_thomson_dtt7579; 23extern struct dvb_pll_desc dvb_pll_thomson_dtt7579;
@@ -23,12 +26,12 @@ extern struct dvb_pll_desc dvb_pll_thomson_dtt7610;
23extern struct dvb_pll_desc dvb_pll_lg_z201; 26extern struct dvb_pll_desc dvb_pll_lg_z201;
24extern struct dvb_pll_desc dvb_pll_unknown_1; 27extern struct dvb_pll_desc dvb_pll_unknown_1;
25 28
29extern struct dvb_pll_desc dvb_pll_tua6010xs;
30extern struct dvb_pll_desc dvb_pll_env57h1xd5;
31extern struct dvb_pll_desc dvb_pll_tua6034;
32extern struct dvb_pll_desc dvb_pll_tda665x;
33
26int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, 34int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
27 u32 freq, int bandwidth); 35 u32 freq, int bandwidth);
28 36
29/* 37#endif
30 * Local variables:
31 * c-basic-offset: 8
32 * compile-command: "make DVB=1"
33 * End:
34 */
diff --git a/drivers/media/dvb/frontends/dvb_dummy_fe.c b/drivers/media/dvb/frontends/dvb_dummy_fe.c
index c05a9b05600c..cff93b9d8ab2 100644
--- a/drivers/media/dvb/frontends/dvb_dummy_fe.c
+++ b/drivers/media/dvb/frontends/dvb_dummy_fe.c
@@ -100,7 +100,7 @@ static int dvb_dummy_fe_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t vo
100 100
101static void dvb_dummy_fe_release(struct dvb_frontend* fe) 101static void dvb_dummy_fe_release(struct dvb_frontend* fe)
102{ 102{
103 struct dvb_dummy_fe_state* state = (struct dvb_dummy_fe_state*) fe->demodulator_priv; 103 struct dvb_dummy_fe_state* state = fe->demodulator_priv;
104 kfree(state); 104 kfree(state);
105} 105}
106 106
@@ -111,7 +111,7 @@ struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)
111 struct dvb_dummy_fe_state* state = NULL; 111 struct dvb_dummy_fe_state* state = NULL;
112 112
113 /* allocate memory for the internal state */ 113 /* allocate memory for the internal state */
114 state = (struct dvb_dummy_fe_state*) kmalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL); 114 state = kmalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
115 if (state == NULL) goto error; 115 if (state == NULL) goto error;
116 116
117 /* setup the state */ 117 /* setup the state */
@@ -134,7 +134,7 @@ struct dvb_frontend* dvb_dummy_fe_qpsk_attach()
134 struct dvb_dummy_fe_state* state = NULL; 134 struct dvb_dummy_fe_state* state = NULL;
135 135
136 /* allocate memory for the internal state */ 136 /* allocate memory for the internal state */
137 state = (struct dvb_dummy_fe_state*) kmalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL); 137 state = kmalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
138 if (state == NULL) goto error; 138 if (state == NULL) goto error;
139 139
140 /* setup the state */ 140 /* setup the state */
@@ -157,7 +157,7 @@ struct dvb_frontend* dvb_dummy_fe_qam_attach()
157 struct dvb_dummy_fe_state* state = NULL; 157 struct dvb_dummy_fe_state* state = NULL;
158 158
159 /* allocate memory for the internal state */ 159 /* allocate memory for the internal state */
160 state = (struct dvb_dummy_fe_state*) kmalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL); 160 state = kmalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
161 if (state == NULL) goto error; 161 if (state == NULL) goto error;
162 162
163 /* setup the state */ 163 /* setup the state */
diff --git a/drivers/media/dvb/frontends/l64781.c b/drivers/media/dvb/frontends/l64781.c
index 9ac95de9834d..031a1ddc7d11 100644
--- a/drivers/media/dvb/frontends/l64781.c
+++ b/drivers/media/dvb/frontends/l64781.c
@@ -121,7 +121,7 @@ static int reset_and_configure (struct l64781_state* state)
121 121
122static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_parameters *param) 122static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_parameters *param)
123{ 123{
124 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 124 struct l64781_state* state = fe->demodulator_priv;
125 /* The coderates for FEC_NONE, FEC_4_5 and FEC_FEC_6_7 are arbitrary */ 125 /* The coderates for FEC_NONE, FEC_4_5 and FEC_FEC_6_7 are arbitrary */
126 static const u8 fec_tab[] = { 7, 0, 1, 2, 9, 3, 10, 4 }; 126 static const u8 fec_tab[] = { 7, 0, 1, 2, 9, 3, 10, 4 };
127 /* QPSK, QAM_16, QAM_64 */ 127 /* QPSK, QAM_16, QAM_64 */
@@ -234,7 +234,7 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
234 234
235static int get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters* param) 235static int get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters* param)
236{ 236{
237 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 237 struct l64781_state* state = fe->demodulator_priv;
238 int tmp; 238 int tmp;
239 239
240 240
@@ -352,7 +352,7 @@ static int get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters*
352 352
353static int l64781_read_status(struct dvb_frontend* fe, fe_status_t* status) 353static int l64781_read_status(struct dvb_frontend* fe, fe_status_t* status)
354{ 354{
355 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 355 struct l64781_state* state = fe->demodulator_priv;
356 int sync = l64781_readreg (state, 0x32); 356 int sync = l64781_readreg (state, 0x32);
357 int gain = l64781_readreg (state, 0x0e); 357 int gain = l64781_readreg (state, 0x0e);
358 358
@@ -381,7 +381,7 @@ static int l64781_read_status(struct dvb_frontend* fe, fe_status_t* status)
381 381
382static int l64781_read_ber(struct dvb_frontend* fe, u32* ber) 382static int l64781_read_ber(struct dvb_frontend* fe, u32* ber)
383{ 383{
384 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 384 struct l64781_state* state = fe->demodulator_priv;
385 385
386 /* XXX FIXME: set up counting period (reg 0x26...0x28) 386 /* XXX FIXME: set up counting period (reg 0x26...0x28)
387 */ 387 */
@@ -393,7 +393,7 @@ static int l64781_read_ber(struct dvb_frontend* fe, u32* ber)
393 393
394static int l64781_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) 394static int l64781_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
395{ 395{
396 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 396 struct l64781_state* state = fe->demodulator_priv;
397 397
398 u8 gain = l64781_readreg (state, 0x0e); 398 u8 gain = l64781_readreg (state, 0x0e);
399 *signal_strength = (gain << 8) | gain; 399 *signal_strength = (gain << 8) | gain;
@@ -403,7 +403,7 @@ static int l64781_read_signal_strength(struct dvb_frontend* fe, u16* signal_stre
403 403
404static int l64781_read_snr(struct dvb_frontend* fe, u16* snr) 404static int l64781_read_snr(struct dvb_frontend* fe, u16* snr)
405{ 405{
406 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 406 struct l64781_state* state = fe->demodulator_priv;
407 407
408 u8 avg_quality = 0xff - l64781_readreg (state, 0x33); 408 u8 avg_quality = 0xff - l64781_readreg (state, 0x33);
409 *snr = (avg_quality << 8) | avg_quality; /* not exact, but...*/ 409 *snr = (avg_quality << 8) | avg_quality; /* not exact, but...*/
@@ -413,7 +413,7 @@ static int l64781_read_snr(struct dvb_frontend* fe, u16* snr)
413 413
414static int l64781_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 414static int l64781_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
415{ 415{
416 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 416 struct l64781_state* state = fe->demodulator_priv;
417 417
418 *ucblocks = l64781_readreg (state, 0x37) 418 *ucblocks = l64781_readreg (state, 0x37)
419 | (l64781_readreg (state, 0x38) << 8); 419 | (l64781_readreg (state, 0x38) << 8);
@@ -423,7 +423,7 @@ static int l64781_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
423 423
424static int l64781_sleep(struct dvb_frontend* fe) 424static int l64781_sleep(struct dvb_frontend* fe)
425{ 425{
426 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 426 struct l64781_state* state = fe->demodulator_priv;
427 427
428 /* Power down */ 428 /* Power down */
429 return l64781_writereg (state, 0x3e, 0x5a); 429 return l64781_writereg (state, 0x3e, 0x5a);
@@ -431,7 +431,7 @@ static int l64781_sleep(struct dvb_frontend* fe)
431 431
432static int l64781_init(struct dvb_frontend* fe) 432static int l64781_init(struct dvb_frontend* fe)
433{ 433{
434 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 434 struct l64781_state* state = fe->demodulator_priv;
435 435
436 reset_and_configure (state); 436 reset_and_configure (state);
437 437
@@ -484,7 +484,7 @@ static int l64781_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend
484 484
485static void l64781_release(struct dvb_frontend* fe) 485static void l64781_release(struct dvb_frontend* fe)
486{ 486{
487 struct l64781_state* state = (struct l64781_state*) fe->demodulator_priv; 487 struct l64781_state* state = fe->demodulator_priv;
488 kfree(state); 488 kfree(state);
489} 489}
490 490
@@ -501,7 +501,7 @@ struct dvb_frontend* l64781_attach(const struct l64781_config* config,
501 { .addr = config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } }; 501 { .addr = config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } };
502 502
503 /* allocate memory for the internal state */ 503 /* allocate memory for the internal state */
504 state = (struct l64781_state*) kmalloc(sizeof(struct l64781_state), GFP_KERNEL); 504 state = kmalloc(sizeof(struct l64781_state), GFP_KERNEL);
505 if (state == NULL) goto error; 505 if (state == NULL) goto error;
506 506
507 /* setup the state */ 507 /* setup the state */
diff --git a/drivers/media/dvb/frontends/mt312.c b/drivers/media/dvb/frontends/mt312.c
index 176a22e3441b..e455aecd76b2 100644
--- a/drivers/media/dvb/frontends/mt312.c
+++ b/drivers/media/dvb/frontends/mt312.c
@@ -226,7 +226,7 @@ static int mt312_get_code_rate(struct mt312_state* state, fe_code_rate_t *cr)
226 226
227static int mt312_initfe(struct dvb_frontend* fe) 227static int mt312_initfe(struct dvb_frontend* fe)
228{ 228{
229 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 229 struct mt312_state *state = fe->demodulator_priv;
230 int ret; 230 int ret;
231 u8 buf[2]; 231 u8 buf[2];
232 232
@@ -287,7 +287,7 @@ static int mt312_initfe(struct dvb_frontend* fe)
287static int mt312_send_master_cmd(struct dvb_frontend* fe, 287static int mt312_send_master_cmd(struct dvb_frontend* fe,
288 struct dvb_diseqc_master_cmd *c) 288 struct dvb_diseqc_master_cmd *c)
289{ 289{
290 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 290 struct mt312_state *state = fe->demodulator_priv;
291 int ret; 291 int ret;
292 u8 diseqc_mode; 292 u8 diseqc_mode;
293 293
@@ -318,7 +318,7 @@ static int mt312_send_master_cmd(struct dvb_frontend* fe,
318 318
319static int mt312_send_burst(struct dvb_frontend* fe, const fe_sec_mini_cmd_t c) 319static int mt312_send_burst(struct dvb_frontend* fe, const fe_sec_mini_cmd_t c)
320{ 320{
321 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 321 struct mt312_state *state = fe->demodulator_priv;
322 const u8 mini_tab[2] = { 0x02, 0x03 }; 322 const u8 mini_tab[2] = { 0x02, 0x03 };
323 323
324 int ret; 324 int ret;
@@ -340,7 +340,7 @@ static int mt312_send_burst(struct dvb_frontend* fe, const fe_sec_mini_cmd_t c)
340 340
341static int mt312_set_tone(struct dvb_frontend* fe, const fe_sec_tone_mode_t t) 341static int mt312_set_tone(struct dvb_frontend* fe, const fe_sec_tone_mode_t t)
342{ 342{
343 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 343 struct mt312_state *state = fe->demodulator_priv;
344 const u8 tone_tab[2] = { 0x01, 0x00 }; 344 const u8 tone_tab[2] = { 0x01, 0x00 };
345 345
346 int ret; 346 int ret;
@@ -362,7 +362,7 @@ static int mt312_set_tone(struct dvb_frontend* fe, const fe_sec_tone_mode_t t)
362 362
363static int mt312_set_voltage(struct dvb_frontend* fe, const fe_sec_voltage_t v) 363static int mt312_set_voltage(struct dvb_frontend* fe, const fe_sec_voltage_t v)
364{ 364{
365 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 365 struct mt312_state *state = fe->demodulator_priv;
366 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 }; 366 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 };
367 367
368 if (v > SEC_VOLTAGE_OFF) 368 if (v > SEC_VOLTAGE_OFF)
@@ -373,7 +373,7 @@ static int mt312_set_voltage(struct dvb_frontend* fe, const fe_sec_voltage_t v)
373 373
374static int mt312_read_status(struct dvb_frontend* fe, fe_status_t *s) 374static int mt312_read_status(struct dvb_frontend* fe, fe_status_t *s)
375{ 375{
376 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 376 struct mt312_state *state = fe->demodulator_priv;
377 int ret; 377 int ret;
378 u8 status[3]; 378 u8 status[3];
379 379
@@ -400,7 +400,7 @@ static int mt312_read_status(struct dvb_frontend* fe, fe_status_t *s)
400 400
401static int mt312_read_ber(struct dvb_frontend* fe, u32 *ber) 401static int mt312_read_ber(struct dvb_frontend* fe, u32 *ber)
402{ 402{
403 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 403 struct mt312_state *state = fe->demodulator_priv;
404 int ret; 404 int ret;
405 u8 buf[3]; 405 u8 buf[3];
406 406
@@ -414,7 +414,7 @@ static int mt312_read_ber(struct dvb_frontend* fe, u32 *ber)
414 414
415static int mt312_read_signal_strength(struct dvb_frontend* fe, u16 *signal_strength) 415static int mt312_read_signal_strength(struct dvb_frontend* fe, u16 *signal_strength)
416{ 416{
417 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 417 struct mt312_state *state = fe->demodulator_priv;
418 int ret; 418 int ret;
419 u8 buf[3]; 419 u8 buf[3];
420 u16 agc; 420 u16 agc;
@@ -435,7 +435,7 @@ static int mt312_read_signal_strength(struct dvb_frontend* fe, u16 *signal_stren
435 435
436static int mt312_read_snr(struct dvb_frontend* fe, u16 *snr) 436static int mt312_read_snr(struct dvb_frontend* fe, u16 *snr)
437{ 437{
438 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 438 struct mt312_state *state = fe->demodulator_priv;
439 int ret; 439 int ret;
440 u8 buf[2]; 440 u8 buf[2];
441 441
@@ -449,7 +449,7 @@ static int mt312_read_snr(struct dvb_frontend* fe, u16 *snr)
449 449
450static int mt312_read_ucblocks(struct dvb_frontend* fe, u32 *ubc) 450static int mt312_read_ucblocks(struct dvb_frontend* fe, u32 *ubc)
451{ 451{
452 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 452 struct mt312_state *state = fe->demodulator_priv;
453 int ret; 453 int ret;
454 u8 buf[2]; 454 u8 buf[2];
455 455
@@ -464,7 +464,7 @@ static int mt312_read_ucblocks(struct dvb_frontend* fe, u32 *ubc)
464static int mt312_set_frontend(struct dvb_frontend* fe, 464static int mt312_set_frontend(struct dvb_frontend* fe,
465 struct dvb_frontend_parameters *p) 465 struct dvb_frontend_parameters *p)
466{ 466{
467 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 467 struct mt312_state *state = fe->demodulator_priv;
468 int ret; 468 int ret;
469 u8 buf[5], config_val; 469 u8 buf[5], config_val;
470 u16 sr; 470 u16 sr;
@@ -560,7 +560,7 @@ static int mt312_set_frontend(struct dvb_frontend* fe,
560static int mt312_get_frontend(struct dvb_frontend* fe, 560static int mt312_get_frontend(struct dvb_frontend* fe,
561 struct dvb_frontend_parameters *p) 561 struct dvb_frontend_parameters *p)
562{ 562{
563 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 563 struct mt312_state *state = fe->demodulator_priv;
564 int ret; 564 int ret;
565 565
566 if ((ret = mt312_get_inversion(state, &p->inversion)) < 0) 566 if ((ret = mt312_get_inversion(state, &p->inversion)) < 0)
@@ -577,7 +577,7 @@ static int mt312_get_frontend(struct dvb_frontend* fe,
577 577
578static int mt312_sleep(struct dvb_frontend* fe) 578static int mt312_sleep(struct dvb_frontend* fe)
579{ 579{
580 struct mt312_state *state = (struct mt312_state*) fe->demodulator_priv; 580 struct mt312_state *state = fe->demodulator_priv;
581 int ret; 581 int ret;
582 u8 config; 582 u8 config;
583 583
@@ -605,7 +605,7 @@ static int mt312_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_
605 605
606static void mt312_release(struct dvb_frontend* fe) 606static void mt312_release(struct dvb_frontend* fe)
607{ 607{
608 struct mt312_state* state = (struct mt312_state*) fe->demodulator_priv; 608 struct mt312_state* state = fe->demodulator_priv;
609 kfree(state); 609 kfree(state);
610} 610}
611 611
@@ -617,7 +617,7 @@ struct dvb_frontend* vp310_attach(const struct mt312_config* config,
617 struct mt312_state* state = NULL; 617 struct mt312_state* state = NULL;
618 618
619 /* allocate memory for the internal state */ 619 /* allocate memory for the internal state */
620 state = (struct mt312_state*) kmalloc(sizeof(struct mt312_state), GFP_KERNEL); 620 state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL);
621 if (state == NULL) 621 if (state == NULL)
622 goto error; 622 goto error;
623 623
@@ -651,7 +651,7 @@ struct dvb_frontend* mt312_attach(const struct mt312_config* config,
651 struct mt312_state* state = NULL; 651 struct mt312_state* state = NULL;
652 652
653 /* allocate memory for the internal state */ 653 /* allocate memory for the internal state */
654 state = (struct mt312_state*) kmalloc(sizeof(struct mt312_state), GFP_KERNEL); 654 state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL);
655 if (state == NULL) 655 if (state == NULL)
656 goto error; 656 goto error;
657 657
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index 50326c7248fa..d32dc4de9e7f 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -46,7 +46,7 @@ struct mt352_state {
46 struct dvb_frontend_ops ops; 46 struct dvb_frontend_ops ops;
47 47
48 /* configuration settings */ 48 /* configuration settings */
49 const struct mt352_config* config; 49 struct mt352_config config;
50}; 50};
51 51
52static int debug; 52static int debug;
@@ -59,7 +59,7 @@ static int mt352_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
59{ 59{
60 struct mt352_state* state = fe->demodulator_priv; 60 struct mt352_state* state = fe->demodulator_priv;
61 u8 buf[2] = { reg, val }; 61 u8 buf[2] = { reg, val };
62 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, 62 struct i2c_msg msg = { .addr = state->config.demod_address, .flags = 0,
63 .buf = buf, .len = 2 }; 63 .buf = buf, .len = 2 };
64 int err = i2c_transfer(state->i2c, &msg, 1); 64 int err = i2c_transfer(state->i2c, &msg, 1);
65 if (err != 1) { 65 if (err != 1) {
@@ -84,10 +84,10 @@ static int mt352_read_register(struct mt352_state* state, u8 reg)
84 int ret; 84 int ret;
85 u8 b0 [] = { reg }; 85 u8 b0 [] = { reg };
86 u8 b1 [] = { 0 }; 86 u8 b1 [] = { 0 };
87 struct i2c_msg msg [] = { { .addr = state->config->demod_address, 87 struct i2c_msg msg [] = { { .addr = state->config.demod_address,
88 .flags = 0, 88 .flags = 0,
89 .buf = b0, .len = 1 }, 89 .buf = b0, .len = 1 },
90 { .addr = state->config->demod_address, 90 { .addr = state->config.demod_address,
91 .flags = I2C_M_RD, 91 .flags = I2C_M_RD,
92 .buf = b1, .len = 1 } }; 92 .buf = b1, .len = 1 } };
93 93
@@ -102,11 +102,6 @@ static int mt352_read_register(struct mt352_state* state, u8 reg)
102 return b1[0]; 102 return b1[0];
103} 103}
104 104
105int mt352_read(struct dvb_frontend *fe, u8 reg)
106{
107 return mt352_read_register(fe->demodulator_priv,reg);
108}
109
110static int mt352_sleep(struct dvb_frontend* fe) 105static int mt352_sleep(struct dvb_frontend* fe)
111{ 106{
112 static u8 mt352_softdown[] = { CLOCK_CTL, 0x20, 0x08 }; 107 static u8 mt352_softdown[] = { CLOCK_CTL, 0x20, 0x08 };
@@ -134,8 +129,8 @@ static void mt352_calc_nominal_rate(struct mt352_state* state,
134 bw = 8; 129 bw = 8;
135 break; 130 break;
136 } 131 }
137 if (state->config->adc_clock) 132 if (state->config.adc_clock)
138 adc_clock = state->config->adc_clock; 133 adc_clock = state->config.adc_clock;
139 134
140 value = 64 * bw * (1<<16) / (7 * 8); 135 value = 64 * bw * (1<<16) / (7 * 8);
141 value = value * 1000 / adc_clock; 136 value = value * 1000 / adc_clock;
@@ -152,10 +147,10 @@ static void mt352_calc_input_freq(struct mt352_state* state,
152 int if2 = 36167; /* 36.166667 MHz */ 147 int if2 = 36167; /* 36.166667 MHz */
153 int ife,value; 148 int ife,value;
154 149
155 if (state->config->adc_clock) 150 if (state->config.adc_clock)
156 adc_clock = state->config->adc_clock; 151 adc_clock = state->config.adc_clock;
157 if (state->config->if2) 152 if (state->config.if2)
158 if2 = state->config->if2; 153 if2 = state->config.if2;
159 154
160 ife = (2*adc_clock - if2); 155 ife = (2*adc_clock - if2);
161 value = -16374 * ife / adc_clock; 156 value = -16374 * ife / adc_clock;
@@ -289,10 +284,10 @@ static int mt352_set_parameters(struct dvb_frontend* fe,
289 284
290 mt352_calc_nominal_rate(state, op->bandwidth, buf+4); 285 mt352_calc_nominal_rate(state, op->bandwidth, buf+4);
291 mt352_calc_input_freq(state, buf+6); 286 mt352_calc_input_freq(state, buf+6);
292 state->config->pll_set(fe, param, buf+8); 287 state->config.pll_set(fe, param, buf+8);
293 288
294 mt352_write(fe, buf, sizeof(buf)); 289 mt352_write(fe, buf, sizeof(buf));
295 if (state->config->no_tuner) { 290 if (state->config.no_tuner) {
296 /* start decoding */ 291 /* start decoding */
297 mt352_write(fe, fsm_go, 2); 292 mt352_write(fe, fsm_go, 2);
298 } else { 293 } else {
@@ -516,7 +511,7 @@ static int mt352_init(struct dvb_frontend* fe)
516 511
517 /* Do a "hard" reset */ 512 /* Do a "hard" reset */
518 mt352_write(fe, mt352_reset_attach, sizeof(mt352_reset_attach)); 513 mt352_write(fe, mt352_reset_attach, sizeof(mt352_reset_attach));
519 return state->config->demod_init(fe); 514 return state->config.demod_init(fe);
520 } 515 }
521 516
522 return 0; 517 return 0;
@@ -541,8 +536,8 @@ struct dvb_frontend* mt352_attach(const struct mt352_config* config,
541 memset(state,0,sizeof(*state)); 536 memset(state,0,sizeof(*state));
542 537
543 /* setup the state */ 538 /* setup the state */
544 state->config = config;
545 state->i2c = i2c; 539 state->i2c = i2c;
540 memcpy(&state->config,config,sizeof(struct mt352_config));
546 memcpy(&state->ops, &mt352_ops, sizeof(struct dvb_frontend_ops)); 541 memcpy(&state->ops, &mt352_ops, sizeof(struct dvb_frontend_ops));
547 542
548 /* check if the demod is there */ 543 /* check if the demod is there */
@@ -601,10 +596,3 @@ MODULE_LICENSE("GPL");
601 596
602EXPORT_SYMBOL(mt352_attach); 597EXPORT_SYMBOL(mt352_attach);
603EXPORT_SYMBOL(mt352_write); 598EXPORT_SYMBOL(mt352_write);
604EXPORT_SYMBOL(mt352_read);
605/*
606 * Local variables:
607 * c-basic-offset: 8
608 * compile-command: "make DVB=1"
609 * End:
610 */
diff --git a/drivers/media/dvb/frontends/mt352.h b/drivers/media/dvb/frontends/mt352.h
index f5d8a5aed8a9..03040cd595bb 100644
--- a/drivers/media/dvb/frontends/mt352.h
+++ b/drivers/media/dvb/frontends/mt352.h
@@ -61,12 +61,5 @@ extern struct dvb_frontend* mt352_attach(const struct mt352_config* config,
61 struct i2c_adapter* i2c); 61 struct i2c_adapter* i2c);
62 62
63extern int mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen); 63extern int mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen);
64extern int mt352_read(struct dvb_frontend *fe, u8 reg);
65 64
66#endif // MT352_H 65#endif // MT352_H
67
68/*
69 * Local variables:
70 * c-basic-offset: 8
71 * End:
72 */
diff --git a/drivers/media/dvb/frontends/nxt2002.c b/drivers/media/dvb/frontends/nxt2002.c
index 4743aa17406e..35a1d60f1927 100644
--- a/drivers/media/dvb/frontends/nxt2002.c
+++ b/drivers/media/dvb/frontends/nxt2002.c
@@ -241,7 +241,7 @@ static void nxt2002_agc_reset(struct nxt2002_state* state)
241static int nxt2002_load_firmware (struct dvb_frontend* fe, const struct firmware *fw) 241static int nxt2002_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
242{ 242{
243 243
244 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 244 struct nxt2002_state* state = fe->demodulator_priv;
245 u8 buf[256],written = 0,chunkpos = 0; 245 u8 buf[256],written = 0,chunkpos = 0;
246 u16 rambase,position,crc = 0; 246 u16 rambase,position,crc = 0;
247 247
@@ -309,7 +309,7 @@ static int nxt2002_load_firmware (struct dvb_frontend* fe, const struct firmware
309static int nxt2002_setup_frontend_parameters (struct dvb_frontend* fe, 309static int nxt2002_setup_frontend_parameters (struct dvb_frontend* fe,
310 struct dvb_frontend_parameters *p) 310 struct dvb_frontend_parameters *p)
311{ 311{
312 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 312 struct nxt2002_state* state = fe->demodulator_priv;
313 u32 freq = 0; 313 u32 freq = 0;
314 u16 tunerfreq = 0; 314 u16 tunerfreq = 0;
315 u8 buf[4]; 315 u8 buf[4];
@@ -343,8 +343,6 @@ static int nxt2002_setup_frontend_parameters (struct dvb_frontend* fe,
343 /* reset the agc now that tuning has been completed */ 343 /* reset the agc now that tuning has been completed */
344 nxt2002_agc_reset(state); 344 nxt2002_agc_reset(state);
345 345
346
347
348 /* set target power level */ 346 /* set target power level */
349 switch (p->u.vsb.modulation) { 347 switch (p->u.vsb.modulation) {
350 case QAM_64: 348 case QAM_64:
@@ -453,7 +451,7 @@ static int nxt2002_setup_frontend_parameters (struct dvb_frontend* fe,
453 451
454static int nxt2002_read_status(struct dvb_frontend* fe, fe_status_t* status) 452static int nxt2002_read_status(struct dvb_frontend* fe, fe_status_t* status)
455{ 453{
456 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 454 struct nxt2002_state* state = fe->demodulator_priv;
457 u8 lock; 455 u8 lock;
458 i2c_readbytes(state,0x31,&lock,1); 456 i2c_readbytes(state,0x31,&lock,1);
459 457
@@ -470,7 +468,7 @@ static int nxt2002_read_status(struct dvb_frontend* fe, fe_status_t* status)
470 468
471static int nxt2002_read_ber(struct dvb_frontend* fe, u32* ber) 469static int nxt2002_read_ber(struct dvb_frontend* fe, u32* ber)
472{ 470{
473 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 471 struct nxt2002_state* state = fe->demodulator_priv;
474 u8 b[3]; 472 u8 b[3];
475 473
476 nxt2002_readreg_multibyte(state,0xE6,b,3); 474 nxt2002_readreg_multibyte(state,0xE6,b,3);
@@ -482,7 +480,7 @@ static int nxt2002_read_ber(struct dvb_frontend* fe, u32* ber)
482 480
483static int nxt2002_read_signal_strength(struct dvb_frontend* fe, u16* strength) 481static int nxt2002_read_signal_strength(struct dvb_frontend* fe, u16* strength)
484{ 482{
485 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 483 struct nxt2002_state* state = fe->demodulator_priv;
486 u8 b[2]; 484 u8 b[2];
487 u16 temp = 0; 485 u16 temp = 0;
488 486
@@ -502,7 +500,7 @@ static int nxt2002_read_signal_strength(struct dvb_frontend* fe, u16* strength)
502static int nxt2002_read_snr(struct dvb_frontend* fe, u16* snr) 500static int nxt2002_read_snr(struct dvb_frontend* fe, u16* snr)
503{ 501{
504 502
505 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 503 struct nxt2002_state* state = fe->demodulator_priv;
506 u8 b[2]; 504 u8 b[2];
507 u16 temp = 0, temp2; 505 u16 temp = 0, temp2;
508 u32 snrdb = 0; 506 u32 snrdb = 0;
@@ -536,7 +534,7 @@ static int nxt2002_read_snr(struct dvb_frontend* fe, u16* snr)
536 534
537static int nxt2002_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 535static int nxt2002_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
538{ 536{
539 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 537 struct nxt2002_state* state = fe->demodulator_priv;
540 u8 b[3]; 538 u8 b[3];
541 539
542 nxt2002_readreg_multibyte(state,0xE6,b,3); 540 nxt2002_readreg_multibyte(state,0xE6,b,3);
@@ -552,7 +550,7 @@ static int nxt2002_sleep(struct dvb_frontend* fe)
552 550
553static int nxt2002_init(struct dvb_frontend* fe) 551static int nxt2002_init(struct dvb_frontend* fe)
554{ 552{
555 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 553 struct nxt2002_state* state = fe->demodulator_priv;
556 const struct firmware *fw; 554 const struct firmware *fw;
557 int ret; 555 int ret;
558 u8 buf[2]; 556 u8 buf[2];
@@ -624,7 +622,7 @@ static int nxt2002_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronten
624 622
625static void nxt2002_release(struct dvb_frontend* fe) 623static void nxt2002_release(struct dvb_frontend* fe)
626{ 624{
627 struct nxt2002_state* state = (struct nxt2002_state*) fe->demodulator_priv; 625 struct nxt2002_state* state = fe->demodulator_priv;
628 kfree(state); 626 kfree(state);
629} 627}
630 628
@@ -637,7 +635,7 @@ struct dvb_frontend* nxt2002_attach(const struct nxt2002_config* config,
637 u8 buf [] = {0,0,0,0,0}; 635 u8 buf [] = {0,0,0,0,0};
638 636
639 /* allocate memory for the internal state */ 637 /* allocate memory for the internal state */
640 state = (struct nxt2002_state*) kmalloc(sizeof(struct nxt2002_state), GFP_KERNEL); 638 state = kmalloc(sizeof(struct nxt2002_state), GFP_KERNEL);
641 if (state == NULL) goto error; 639 if (state == NULL) goto error;
642 640
643 /* setup the state */ 641 /* setup the state */
diff --git a/drivers/media/dvb/frontends/nxt6000.c b/drivers/media/dvb/frontends/nxt6000.c
index a41f7da8b842..966de9853d18 100644
--- a/drivers/media/dvb/frontends/nxt6000.c
+++ b/drivers/media/dvb/frontends/nxt6000.c
@@ -176,11 +176,16 @@ static int nxt6000_set_transmission_mode(struct nxt6000_state* state, fe_transmi
176 176
177static void nxt6000_setup(struct dvb_frontend* fe) 177static void nxt6000_setup(struct dvb_frontend* fe)
178{ 178{
179 struct nxt6000_state* state = (struct nxt6000_state*) fe->demodulator_priv; 179 struct nxt6000_state* state = fe->demodulator_priv;
180 180
181 nxt6000_writereg(state, RS_COR_SYNC_PARAM, SYNC_PARAM); 181 nxt6000_writereg(state, RS_COR_SYNC_PARAM, SYNC_PARAM);
182 nxt6000_writereg(state, BER_CTRL, /*(1 << 2) | */ (0x01 << 1) | 0x01); 182 nxt6000_writereg(state, BER_CTRL, /*(1 << 2) | */ (0x01 << 1) | 0x01);
183 nxt6000_writereg(state, VIT_COR_CTL, VIT_COR_RESYNC); 183 nxt6000_writereg(state, VIT_BERTIME_2, 0x00); // BER Timer = 0x000200 * 256 = 131072 bits
184 nxt6000_writereg(state, VIT_BERTIME_1, 0x02); //
185 nxt6000_writereg(state, VIT_BERTIME_0, 0x00); //
186 nxt6000_writereg(state, VIT_COR_INTEN, 0x98); // Enable BER interrupts
187 nxt6000_writereg(state, VIT_COR_CTL, 0x82); // Enable BER measurement
188 nxt6000_writereg(state, VIT_COR_CTL, VIT_COR_RESYNC | 0x02 );
184 nxt6000_writereg(state, OFDM_COR_CTL, (0x01 << 5) | (nxt6000_readreg(state, OFDM_COR_CTL) & 0x0F)); 189 nxt6000_writereg(state, OFDM_COR_CTL, (0x01 << 5) | (nxt6000_readreg(state, OFDM_COR_CTL) & 0x0F));
185 nxt6000_writereg(state, OFDM_COR_MODEGUARD, FORCEMODE8K | 0x02); 190 nxt6000_writereg(state, OFDM_COR_MODEGUARD, FORCEMODE8K | 0x02);
186 nxt6000_writereg(state, OFDM_AGC_CTL, AGCLAST | INITIAL_AGC_BW); 191 nxt6000_writereg(state, OFDM_AGC_CTL, AGCLAST | INITIAL_AGC_BW);
@@ -422,7 +427,7 @@ static void nxt6000_dump_status(struct nxt6000_state *state)
422static int nxt6000_read_status(struct dvb_frontend* fe, fe_status_t* status) 427static int nxt6000_read_status(struct dvb_frontend* fe, fe_status_t* status)
423{ 428{
424 u8 core_status; 429 u8 core_status;
425 struct nxt6000_state* state = (struct nxt6000_state*) fe->demodulator_priv; 430 struct nxt6000_state* state = fe->demodulator_priv;
426 431
427 *status = 0; 432 *status = 0;
428 433
@@ -451,7 +456,7 @@ static int nxt6000_read_status(struct dvb_frontend* fe, fe_status_t* status)
451 456
452static int nxt6000_init(struct dvb_frontend* fe) 457static int nxt6000_init(struct dvb_frontend* fe)
453{ 458{
454 struct nxt6000_state* state = (struct nxt6000_state*) fe->demodulator_priv; 459 struct nxt6000_state* state = fe->demodulator_priv;
455 460
456 nxt6000_reset(state); 461 nxt6000_reset(state);
457 nxt6000_setup(fe); 462 nxt6000_setup(fe);
@@ -461,7 +466,7 @@ static int nxt6000_init(struct dvb_frontend* fe)
461 466
462static int nxt6000_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *param) 467static int nxt6000_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *param)
463{ 468{
464 struct nxt6000_state* state = (struct nxt6000_state*) fe->demodulator_priv; 469 struct nxt6000_state* state = fe->demodulator_priv;
465 int result; 470 int result;
466 471
467 nxt6000_writereg(state, ENABLE_TUNER_IIC, 0x01); /* open i2c bus switch */ 472 nxt6000_writereg(state, ENABLE_TUNER_IIC, 0x01); /* open i2c bus switch */
@@ -482,10 +487,44 @@ static int nxt6000_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
482 487
483static void nxt6000_release(struct dvb_frontend* fe) 488static void nxt6000_release(struct dvb_frontend* fe)
484{ 489{
485 struct nxt6000_state* state = (struct nxt6000_state*) fe->demodulator_priv; 490 struct nxt6000_state* state = fe->demodulator_priv;
486 kfree(state); 491 kfree(state);
487} 492}
488 493
494static int nxt6000_read_snr(struct dvb_frontend* fe, u16* snr)
495{
496 struct nxt6000_state* state = fe->demodulator_priv;
497
498 *snr = nxt6000_readreg( state, OFDM_CHC_SNR) / 8;
499
500 return 0;
501}
502
503static int nxt6000_read_ber(struct dvb_frontend* fe, u32* ber)
504{
505 struct nxt6000_state* state = fe->demodulator_priv;
506
507 nxt6000_writereg( state, VIT_COR_INTSTAT, 0x18 );
508
509 *ber = (nxt6000_readreg( state, VIT_BER_1 ) << 8 ) |
510 nxt6000_readreg( state, VIT_BER_0 );
511
512 nxt6000_writereg( state, VIT_COR_INTSTAT, 0x18); // Clear BER Done interrupts
513
514 return 0;
515}
516
517static int nxt6000_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
518{
519 struct nxt6000_state* state = fe->demodulator_priv;
520
521 *signal_strength = (short) (511 -
522 (nxt6000_readreg(state, AGC_GAIN_1) +
523 ((nxt6000_readreg(state, AGC_GAIN_2) & 0x03) << 8)));
524
525 return 0;
526}
527
489static struct dvb_frontend_ops nxt6000_ops; 528static struct dvb_frontend_ops nxt6000_ops;
490 529
491struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config, 530struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
@@ -494,7 +533,7 @@ struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
494 struct nxt6000_state* state = NULL; 533 struct nxt6000_state* state = NULL;
495 534
496 /* allocate memory for the internal state */ 535 /* allocate memory for the internal state */
497 state = (struct nxt6000_state*) kmalloc(sizeof(struct nxt6000_state), GFP_KERNEL); 536 state = kmalloc(sizeof(struct nxt6000_state), GFP_KERNEL);
498 if (state == NULL) goto error; 537 if (state == NULL) goto error;
499 538
500 /* setup the state */ 539 /* setup the state */
@@ -542,6 +581,9 @@ static struct dvb_frontend_ops nxt6000_ops = {
542 .set_frontend = nxt6000_set_frontend, 581 .set_frontend = nxt6000_set_frontend,
543 582
544 .read_status = nxt6000_read_status, 583 .read_status = nxt6000_read_status,
584 .read_ber = nxt6000_read_ber,
585 .read_signal_strength = nxt6000_read_signal_strength,
586 .read_snr = nxt6000_read_snr,
545}; 587};
546 588
547module_param(debug, int, 0644); 589module_param(debug, int, 0644);
diff --git a/drivers/media/dvb/frontends/nxt6000_priv.h b/drivers/media/dvb/frontends/nxt6000_priv.h
index 64b1a89b2a22..0422e580038a 100644
--- a/drivers/media/dvb/frontends/nxt6000_priv.h
+++ b/drivers/media/dvb/frontends/nxt6000_priv.h
@@ -65,12 +65,27 @@
65#define BER_DONE (0x08) 65#define BER_DONE (0x08)
66#define BER_OVERFLOW (0x10) 66#define BER_OVERFLOW (0x10)
67 67
68/* 0x38 VIT_BERTIME_2 */
69#define VIT_BERTIME_2 (0x38)
70
71/* 0x39 VIT_BERTIME_1 */
72#define VIT_BERTIME_1 (0x39)
73
74/* 0x3A VIT_BERTIME_0 */
75#define VIT_BERTIME_0 (0x3a)
76
68 /* 0x38 OFDM_BERTimer *//* Use the alias registers */ 77 /* 0x38 OFDM_BERTimer *//* Use the alias registers */
69#define A_VIT_BER_TIMER_0 (0x1D) 78#define A_VIT_BER_TIMER_0 (0x1D)
70 79
71 /* 0x3A VIT_BER_TIMER_0 *//* Use the alias registers */ 80 /* 0x3A VIT_BER_TIMER_0 *//* Use the alias registers */
72#define A_VIT_BER_0 (0x1B) 81#define A_VIT_BER_0 (0x1B)
73 82
83/* 0x3B VIT_BER_1 */
84#define VIT_BER_1 (0x3b)
85
86/* 0x3C VIT_BER_0 */
87#define VIT_BER_0 (0x3c)
88
74/* 0x40 OFDM_COR_CTL */ 89/* 0x40 OFDM_COR_CTL */
75#define OFDM_COR_CTL (0x40) 90#define OFDM_COR_CTL (0x40)
76#define COREACT (0x20) 91#define COREACT (0x20)
@@ -117,6 +132,12 @@
117#define OFDM_ITB_CTL (0x4B) 132#define OFDM_ITB_CTL (0x4B)
118#define ITBINV (0x01) 133#define ITBINV (0x01)
119 134
135/* 0x49 AGC_GAIN_1 */
136#define AGC_GAIN_1 (0x49)
137
138/* 0x4A AGC_GAIN_2 */
139#define AGC_GAIN_2 (0x4A)
140
120/* 0x4C OFDM_ITB_FREQ_1 */ 141/* 0x4C OFDM_ITB_FREQ_1 */
121#define OFDM_ITB_FREQ_1 (0x4C) 142#define OFDM_ITB_FREQ_1 (0x4C)
122 143
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index df5dee7760a3..cc0a77c790f1 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -102,7 +102,7 @@ static u8 i2c_readbytes (struct or51132_state* state, u8 reg, u8* buf, int len)
102 102
103static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware *fw) 103static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
104{ 104{
105 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; 105 struct or51132_state* state = fe->demodulator_priv;
106 static u8 run_buf[] = {0x7F,0x01}; 106 static u8 run_buf[] = {0x7F,0x01};
107 static u8 get_ver_buf[] = {0x04,0x00,0x30,0x00,0x00}; 107 static u8 get_ver_buf[] = {0x04,0x00,0x30,0x00,0x00};
108 u8 rec_buf[14]; 108 u8 rec_buf[14];
@@ -240,7 +240,7 @@ static int or51132_sleep(struct dvb_frontend* fe)
240 240
241static int or51132_setmode(struct dvb_frontend* fe) 241static int or51132_setmode(struct dvb_frontend* fe)
242{ 242{
243 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; 243 struct or51132_state* state = fe->demodulator_priv;
244 unsigned char cmd_buf[4]; 244 unsigned char cmd_buf[4];
245 245
246 dprintk("setmode %d\n",(int)state->current_modulation); 246 dprintk("setmode %d\n",(int)state->current_modulation);
@@ -316,7 +316,7 @@ static int or51132_set_parameters(struct dvb_frontend* fe,
316{ 316{
317 int ret; 317 int ret;
318 u8 buf[4]; 318 u8 buf[4];
319 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; 319 struct or51132_state* state = fe->demodulator_priv;
320 const struct firmware *fw; 320 const struct firmware *fw;
321 321
322 /* Change only if we are actually changing the modulation */ 322 /* Change only if we are actually changing the modulation */
@@ -391,7 +391,7 @@ static int or51132_set_parameters(struct dvb_frontend* fe,
391 391
392static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status) 392static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status)
393{ 393{
394 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; 394 struct or51132_state* state = fe->demodulator_priv;
395 unsigned char rec_buf[2]; 395 unsigned char rec_buf[2];
396 unsigned char snd_buf[2]; 396 unsigned char snd_buf[2];
397 *status = 0; 397 *status = 0;
@@ -464,7 +464,7 @@ static unsigned int i20Log10(unsigned short val)
464 464
465static int or51132_read_signal_strength(struct dvb_frontend* fe, u16* strength) 465static int or51132_read_signal_strength(struct dvb_frontend* fe, u16* strength)
466{ 466{
467 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; 467 struct or51132_state* state = fe->demodulator_priv;
468 unsigned char rec_buf[2]; 468 unsigned char rec_buf[2];
469 unsigned char snd_buf[2]; 469 unsigned char snd_buf[2];
470 u8 rcvr_stat; 470 u8 rcvr_stat;
@@ -512,7 +512,7 @@ static int or51132_read_signal_strength(struct dvb_frontend* fe, u16* strength)
512 512
513static int or51132_read_snr(struct dvb_frontend* fe, u16* snr) 513static int or51132_read_snr(struct dvb_frontend* fe, u16* snr)
514{ 514{
515 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; 515 struct or51132_state* state = fe->demodulator_priv;
516 unsigned char rec_buf[2]; 516 unsigned char rec_buf[2];
517 unsigned char snd_buf[2]; 517 unsigned char snd_buf[2];
518 u16 snr_equ; 518 u16 snr_equ;
@@ -549,7 +549,7 @@ static int or51132_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronten
549 549
550static void or51132_release(struct dvb_frontend* fe) 550static void or51132_release(struct dvb_frontend* fe)
551{ 551{
552 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv; 552 struct or51132_state* state = fe->demodulator_priv;
553 kfree(state); 553 kfree(state);
554} 554}
555 555
diff --git a/drivers/media/dvb/frontends/sp8870.c b/drivers/media/dvb/frontends/sp8870.c
index 58ad34ef0a00..764a95a2e212 100644
--- a/drivers/media/dvb/frontends/sp8870.c
+++ b/drivers/media/dvb/frontends/sp8870.c
@@ -248,7 +248,7 @@ static int sp8870_wake_up(struct sp8870_state* state)
248static int sp8870_set_frontend_parameters (struct dvb_frontend* fe, 248static int sp8870_set_frontend_parameters (struct dvb_frontend* fe,
249 struct dvb_frontend_parameters *p) 249 struct dvb_frontend_parameters *p)
250{ 250{
251 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 251 struct sp8870_state* state = fe->demodulator_priv;
252 int err; 252 int err;
253 u16 reg0xc05; 253 u16 reg0xc05;
254 254
@@ -302,7 +302,7 @@ static int sp8870_set_frontend_parameters (struct dvb_frontend* fe,
302 302
303static int sp8870_init (struct dvb_frontend* fe) 303static int sp8870_init (struct dvb_frontend* fe)
304{ 304{
305 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 305 struct sp8870_state* state = fe->demodulator_priv;
306 const struct firmware *fw = NULL; 306 const struct firmware *fw = NULL;
307 307
308 sp8870_wake_up(state); 308 sp8870_wake_up(state);
@@ -358,7 +358,7 @@ static int sp8870_init (struct dvb_frontend* fe)
358 358
359static int sp8870_read_status (struct dvb_frontend* fe, fe_status_t * fe_status) 359static int sp8870_read_status (struct dvb_frontend* fe, fe_status_t * fe_status)
360{ 360{
361 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 361 struct sp8870_state* state = fe->demodulator_priv;
362 int status; 362 int status;
363 int signal; 363 int signal;
364 364
@@ -384,7 +384,7 @@ static int sp8870_read_status (struct dvb_frontend* fe, fe_status_t * fe_status)
384 384
385static int sp8870_read_ber (struct dvb_frontend* fe, u32 * ber) 385static int sp8870_read_ber (struct dvb_frontend* fe, u32 * ber)
386{ 386{
387 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 387 struct sp8870_state* state = fe->demodulator_priv;
388 int ret; 388 int ret;
389 u32 tmp; 389 u32 tmp;
390 390
@@ -412,7 +412,7 @@ static int sp8870_read_ber (struct dvb_frontend* fe, u32 * ber)
412 412
413static int sp8870_read_signal_strength(struct dvb_frontend* fe, u16 * signal) 413static int sp8870_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
414{ 414{
415 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 415 struct sp8870_state* state = fe->demodulator_priv;
416 int ret; 416 int ret;
417 u16 tmp; 417 u16 tmp;
418 418
@@ -438,7 +438,7 @@ static int sp8870_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
438 438
439static int sp8870_read_uncorrected_blocks (struct dvb_frontend* fe, u32* ublocks) 439static int sp8870_read_uncorrected_blocks (struct dvb_frontend* fe, u32* ublocks)
440{ 440{
441 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 441 struct sp8870_state* state = fe->demodulator_priv;
442 int ret; 442 int ret;
443 443
444 *ublocks = 0; 444 *ublocks = 0;
@@ -467,7 +467,7 @@ static int switches = 0;
467 467
468static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 468static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
469{ 469{
470 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 470 struct sp8870_state* state = fe->demodulator_priv;
471 471
472 /* 472 /*
473 The firmware of the sp8870 sometimes locks up after setting frontend parameters. 473 The firmware of the sp8870 sometimes locks up after setting frontend parameters.
@@ -524,7 +524,7 @@ static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_par
524 524
525static int sp8870_sleep(struct dvb_frontend* fe) 525static int sp8870_sleep(struct dvb_frontend* fe)
526{ 526{
527 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 527 struct sp8870_state* state = fe->demodulator_priv;
528 528
529 // tristate TS output and disable interface pins 529 // tristate TS output and disable interface pins
530 return sp8870_writereg(state, 0xC18, 0x000); 530 return sp8870_writereg(state, 0xC18, 0x000);
@@ -540,7 +540,7 @@ static int sp8870_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend
540 540
541static void sp8870_release(struct dvb_frontend* fe) 541static void sp8870_release(struct dvb_frontend* fe)
542{ 542{
543 struct sp8870_state* state = (struct sp8870_state*) fe->demodulator_priv; 543 struct sp8870_state* state = fe->demodulator_priv;
544 kfree(state); 544 kfree(state);
545} 545}
546 546
@@ -552,7 +552,7 @@ struct dvb_frontend* sp8870_attach(const struct sp8870_config* config,
552 struct sp8870_state* state = NULL; 552 struct sp8870_state* state = NULL;
553 553
554 /* allocate memory for the internal state */ 554 /* allocate memory for the internal state */
555 state = (struct sp8870_state*) kmalloc(sizeof(struct sp8870_state), GFP_KERNEL); 555 state = kmalloc(sizeof(struct sp8870_state), GFP_KERNEL);
556 if (state == NULL) goto error; 556 if (state == NULL) goto error;
557 557
558 /* setup the state */ 558 /* setup the state */
diff --git a/drivers/media/dvb/frontends/sp887x.c b/drivers/media/dvb/frontends/sp887x.c
index 7eae833ece49..d868a6927a16 100644
--- a/drivers/media/dvb/frontends/sp887x.c
+++ b/drivers/media/dvb/frontends/sp887x.c
@@ -135,7 +135,7 @@ static void sp887x_setup_agc (struct sp887x_state* state)
135 */ 135 */
136static int sp887x_initial_setup (struct dvb_frontend* fe, const struct firmware *fw) 136static int sp887x_initial_setup (struct dvb_frontend* fe, const struct firmware *fw)
137{ 137{
138 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 138 struct sp887x_state* state = fe->demodulator_priv;
139 u8 buf [BLOCKSIZE+2]; 139 u8 buf [BLOCKSIZE+2];
140 int i; 140 int i;
141 int fw_size = fw->size; 141 int fw_size = fw->size;
@@ -344,7 +344,7 @@ static void sp887x_correct_offsets (struct sp887x_state* state,
344static int sp887x_setup_frontend_parameters (struct dvb_frontend* fe, 344static int sp887x_setup_frontend_parameters (struct dvb_frontend* fe,
345 struct dvb_frontend_parameters *p) 345 struct dvb_frontend_parameters *p)
346{ 346{
347 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 347 struct sp887x_state* state = fe->demodulator_priv;
348 int actual_freq, err; 348 int actual_freq, err;
349 u16 val, reg0xc05; 349 u16 val, reg0xc05;
350 350
@@ -405,7 +405,7 @@ static int sp887x_setup_frontend_parameters (struct dvb_frontend* fe,
405 405
406static int sp887x_read_status(struct dvb_frontend* fe, fe_status_t* status) 406static int sp887x_read_status(struct dvb_frontend* fe, fe_status_t* status)
407{ 407{
408 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 408 struct sp887x_state* state = fe->demodulator_priv;
409 u16 snr12 = sp887x_readreg(state, 0xf16); 409 u16 snr12 = sp887x_readreg(state, 0xf16);
410 u16 sync0x200 = sp887x_readreg(state, 0x200); 410 u16 sync0x200 = sp887x_readreg(state, 0x200);
411 u16 sync0xf17 = sp887x_readreg(state, 0xf17); 411 u16 sync0xf17 = sp887x_readreg(state, 0xf17);
@@ -439,7 +439,7 @@ static int sp887x_read_status(struct dvb_frontend* fe, fe_status_t* status)
439 439
440static int sp887x_read_ber(struct dvb_frontend* fe, u32* ber) 440static int sp887x_read_ber(struct dvb_frontend* fe, u32* ber)
441{ 441{
442 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 442 struct sp887x_state* state = fe->demodulator_priv;
443 443
444 *ber = (sp887x_readreg(state, 0xc08) & 0x3f) | 444 *ber = (sp887x_readreg(state, 0xc08) & 0x3f) |
445 (sp887x_readreg(state, 0xc07) << 6); 445 (sp887x_readreg(state, 0xc07) << 6);
@@ -453,7 +453,7 @@ static int sp887x_read_ber(struct dvb_frontend* fe, u32* ber)
453 453
454static int sp887x_read_signal_strength(struct dvb_frontend* fe, u16* strength) 454static int sp887x_read_signal_strength(struct dvb_frontend* fe, u16* strength)
455{ 455{
456 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 456 struct sp887x_state* state = fe->demodulator_priv;
457 457
458 u16 snr12 = sp887x_readreg(state, 0xf16); 458 u16 snr12 = sp887x_readreg(state, 0xf16);
459 u32 signal = 3 * (snr12 << 4); 459 u32 signal = 3 * (snr12 << 4);
@@ -464,7 +464,7 @@ static int sp887x_read_signal_strength(struct dvb_frontend* fe, u16* strength)
464 464
465static int sp887x_read_snr(struct dvb_frontend* fe, u16* snr) 465static int sp887x_read_snr(struct dvb_frontend* fe, u16* snr)
466{ 466{
467 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 467 struct sp887x_state* state = fe->demodulator_priv;
468 468
469 u16 snr12 = sp887x_readreg(state, 0xf16); 469 u16 snr12 = sp887x_readreg(state, 0xf16);
470 *snr = (snr12 << 4) | (snr12 >> 8); 470 *snr = (snr12 << 4) | (snr12 >> 8);
@@ -474,7 +474,7 @@ static int sp887x_read_snr(struct dvb_frontend* fe, u16* snr)
474 474
475static int sp887x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 475static int sp887x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
476{ 476{
477 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 477 struct sp887x_state* state = fe->demodulator_priv;
478 478
479 *ucblocks = sp887x_readreg(state, 0xc0c); 479 *ucblocks = sp887x_readreg(state, 0xc0c);
480 if (*ucblocks == 0xfff) 480 if (*ucblocks == 0xfff)
@@ -485,7 +485,7 @@ static int sp887x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
485 485
486static int sp887x_sleep(struct dvb_frontend* fe) 486static int sp887x_sleep(struct dvb_frontend* fe)
487{ 487{
488 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 488 struct sp887x_state* state = fe->demodulator_priv;
489 489
490 /* tristate TS output and disable interface pins */ 490 /* tristate TS output and disable interface pins */
491 sp887x_writereg(state, 0xc18, 0x000); 491 sp887x_writereg(state, 0xc18, 0x000);
@@ -495,7 +495,7 @@ static int sp887x_sleep(struct dvb_frontend* fe)
495 495
496static int sp887x_init(struct dvb_frontend* fe) 496static int sp887x_init(struct dvb_frontend* fe)
497{ 497{
498 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 498 struct sp887x_state* state = fe->demodulator_priv;
499 const struct firmware *fw = NULL; 499 const struct firmware *fw = NULL;
500 int ret; 500 int ret;
501 501
@@ -534,7 +534,7 @@ static int sp887x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend
534 534
535static void sp887x_release(struct dvb_frontend* fe) 535static void sp887x_release(struct dvb_frontend* fe)
536{ 536{
537 struct sp887x_state* state = (struct sp887x_state*) fe->demodulator_priv; 537 struct sp887x_state* state = fe->demodulator_priv;
538 kfree(state); 538 kfree(state);
539} 539}
540 540
@@ -546,7 +546,7 @@ struct dvb_frontend* sp887x_attach(const struct sp887x_config* config,
546 struct sp887x_state* state = NULL; 546 struct sp887x_state* state = NULL;
547 547
548 /* allocate memory for the internal state */ 548 /* allocate memory for the internal state */
549 state = (struct sp887x_state*) kmalloc(sizeof(struct sp887x_state), GFP_KERNEL); 549 state = kmalloc(sizeof(struct sp887x_state), GFP_KERNEL);
550 if (state == NULL) goto error; 550 if (state == NULL) goto error;
551 551
552 /* setup the state */ 552 /* setup the state */
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index 502c6403dfc6..e681263bf079 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -365,7 +365,7 @@ static int stv0297_set_inversion(struct stv0297_state *state, fe_spectral_invers
365 365
366int stv0297_enable_plli2c(struct dvb_frontend *fe) 366int stv0297_enable_plli2c(struct dvb_frontend *fe)
367{ 367{
368 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 368 struct stv0297_state *state = fe->demodulator_priv;
369 369
370 stv0297_writereg(state, 0x87, 0x78); 370 stv0297_writereg(state, 0x87, 0x78);
371 stv0297_writereg(state, 0x86, 0xc8); 371 stv0297_writereg(state, 0x86, 0xc8);
@@ -375,7 +375,7 @@ int stv0297_enable_plli2c(struct dvb_frontend *fe)
375 375
376static int stv0297_init(struct dvb_frontend *fe) 376static int stv0297_init(struct dvb_frontend *fe)
377{ 377{
378 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 378 struct stv0297_state *state = fe->demodulator_priv;
379 int i; 379 int i;
380 380
381 /* soft reset */ 381 /* soft reset */
@@ -416,7 +416,7 @@ static int stv0297_init(struct dvb_frontend *fe)
416 416
417static int stv0297_sleep(struct dvb_frontend *fe) 417static int stv0297_sleep(struct dvb_frontend *fe)
418{ 418{
419 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 419 struct stv0297_state *state = fe->demodulator_priv;
420 420
421 stv0297_writereg_mask(state, 0x80, 1, 1); 421 stv0297_writereg_mask(state, 0x80, 1, 1);
422 422
@@ -425,7 +425,7 @@ static int stv0297_sleep(struct dvb_frontend *fe)
425 425
426static int stv0297_read_status(struct dvb_frontend *fe, fe_status_t * status) 426static int stv0297_read_status(struct dvb_frontend *fe, fe_status_t * status)
427{ 427{
428 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 428 struct stv0297_state *state = fe->demodulator_priv;
429 429
430 u8 sync = stv0297_readreg(state, 0xDF); 430 u8 sync = stv0297_readreg(state, 0xDF);
431 431
@@ -438,7 +438,7 @@ static int stv0297_read_status(struct dvb_frontend *fe, fe_status_t * status)
438 438
439static int stv0297_read_ber(struct dvb_frontend *fe, u32 * ber) 439static int stv0297_read_ber(struct dvb_frontend *fe, u32 * ber)
440{ 440{
441 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 441 struct stv0297_state *state = fe->demodulator_priv;
442 u8 BER[3]; 442 u8 BER[3];
443 443
444 stv0297_writereg(state, 0xA0, 0x80); // Start Counting bit errors for 4096 Bytes 444 stv0297_writereg(state, 0xA0, 0x80); // Start Counting bit errors for 4096 Bytes
@@ -453,7 +453,7 @@ static int stv0297_read_ber(struct dvb_frontend *fe, u32 * ber)
453 453
454static int stv0297_read_signal_strength(struct dvb_frontend *fe, u16 * strength) 454static int stv0297_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
455{ 455{
456 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 456 struct stv0297_state *state = fe->demodulator_priv;
457 u8 STRENGTH[2]; 457 u8 STRENGTH[2];
458 458
459 stv0297_readregs(state, 0x41, STRENGTH, 2); 459 stv0297_readregs(state, 0x41, STRENGTH, 2);
@@ -464,7 +464,7 @@ static int stv0297_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
464 464
465static int stv0297_read_snr(struct dvb_frontend *fe, u16 * snr) 465static int stv0297_read_snr(struct dvb_frontend *fe, u16 * snr)
466{ 466{
467 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 467 struct stv0297_state *state = fe->demodulator_priv;
468 u8 SNR[2]; 468 u8 SNR[2];
469 469
470 stv0297_readregs(state, 0x07, SNR, 2); 470 stv0297_readregs(state, 0x07, SNR, 2);
@@ -475,7 +475,7 @@ static int stv0297_read_snr(struct dvb_frontend *fe, u16 * snr)
475 475
476static int stv0297_read_ucblocks(struct dvb_frontend *fe, u32 * ucblocks) 476static int stv0297_read_ucblocks(struct dvb_frontend *fe, u32 * ucblocks)
477{ 477{
478 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 478 struct stv0297_state *state = fe->demodulator_priv;
479 479
480 *ucblocks = (stv0297_readreg(state, 0xD5) << 8) 480 *ucblocks = (stv0297_readreg(state, 0xD5) << 8)
481 | stv0297_readreg(state, 0xD4); 481 | stv0297_readreg(state, 0xD4);
@@ -485,7 +485,7 @@ static int stv0297_read_ucblocks(struct dvb_frontend *fe, u32 * ucblocks)
485 485
486static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p) 486static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
487{ 487{
488 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 488 struct stv0297_state *state = fe->demodulator_priv;
489 int u_threshold; 489 int u_threshold;
490 int initial_u; 490 int initial_u;
491 int blind_u; 491 int blind_u;
@@ -689,7 +689,7 @@ timeout:
689 689
690static int stv0297_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p) 690static int stv0297_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
691{ 691{
692 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 692 struct stv0297_state *state = fe->demodulator_priv;
693 int reg_00, reg_83; 693 int reg_00, reg_83;
694 694
695 reg_00 = stv0297_readreg(state, 0x00); 695 reg_00 = stv0297_readreg(state, 0x00);
@@ -725,7 +725,7 @@ static int stv0297_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
725 725
726static void stv0297_release(struct dvb_frontend *fe) 726static void stv0297_release(struct dvb_frontend *fe)
727{ 727{
728 struct stv0297_state *state = (struct stv0297_state *) fe->demodulator_priv; 728 struct stv0297_state *state = fe->demodulator_priv;
729 kfree(state); 729 kfree(state);
730} 730}
731 731
@@ -737,7 +737,7 @@ struct dvb_frontend *stv0297_attach(const struct stv0297_config *config,
737 struct stv0297_state *state = NULL; 737 struct stv0297_state *state = NULL;
738 738
739 /* allocate memory for the internal state */ 739 /* allocate memory for the internal state */
740 state = (struct stv0297_state *) kmalloc(sizeof(struct stv0297_state), GFP_KERNEL); 740 state = kmalloc(sizeof(struct stv0297_state), GFP_KERNEL);
741 if (state == NULL) 741 if (state == NULL)
742 goto error; 742 goto error;
743 743
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 15b40541b62d..cfa3928bb487 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -70,6 +70,7 @@ struct stv0299_state {
70#define STATUS_UCBLOCKS 1 70#define STATUS_UCBLOCKS 1
71 71
72static int debug; 72static int debug;
73static int debug_legacy_dish_switch;
73#define dprintk(args...) \ 74#define dprintk(args...) \
74 do { \ 75 do { \
75 if (debug) printk(KERN_DEBUG "stv0299: " args); \ 76 if (debug) printk(KERN_DEBUG "stv0299: " args); \
@@ -93,7 +94,7 @@ static int stv0299_writeregI (struct stv0299_state* state, u8 reg, u8 data)
93 94
94int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data) 95int stv0299_writereg (struct dvb_frontend* fe, u8 reg, u8 data)
95{ 96{
96 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 97 struct stv0299_state* state = fe->demodulator_priv;
97 98
98 return stv0299_writeregI(state, reg, data); 99 return stv0299_writeregI(state, reg, data);
99} 100}
@@ -218,7 +219,7 @@ static int stv0299_wait_diseqc_idle (struct stv0299_state* state, int timeout)
218 219
219static int stv0299_set_symbolrate (struct dvb_frontend* fe, u32 srate) 220static int stv0299_set_symbolrate (struct dvb_frontend* fe, u32 srate)
220{ 221{
221 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 222 struct stv0299_state* state = fe->demodulator_priv;
222 u64 big = srate; 223 u64 big = srate;
223 u32 ratio; 224 u32 ratio;
224 225
@@ -269,7 +270,7 @@ static int stv0299_get_symbolrate (struct stv0299_state* state)
269static int stv0299_send_diseqc_msg (struct dvb_frontend* fe, 270static int stv0299_send_diseqc_msg (struct dvb_frontend* fe,
270 struct dvb_diseqc_master_cmd *m) 271 struct dvb_diseqc_master_cmd *m)
271{ 272{
272 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 273 struct stv0299_state* state = fe->demodulator_priv;
273 u8 val; 274 u8 val;
274 int i; 275 int i;
275 276
@@ -299,7 +300,7 @@ static int stv0299_send_diseqc_msg (struct dvb_frontend* fe,
299 300
300static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 301static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
301{ 302{
302 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 303 struct stv0299_state* state = fe->demodulator_priv;
303 u8 val; 304 u8 val;
304 305
305 dprintk ("%s\n", __FUNCTION__); 306 dprintk ("%s\n", __FUNCTION__);
@@ -326,7 +327,7 @@ static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t
326 327
327static int stv0299_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 328static int stv0299_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
328{ 329{
329 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 330 struct stv0299_state* state = fe->demodulator_priv;
330 u8 val; 331 u8 val;
331 332
332 if (stv0299_wait_diseqc_idle (state, 100) < 0) 333 if (stv0299_wait_diseqc_idle (state, 100) < 0)
@@ -348,7 +349,7 @@ static int stv0299_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
348 349
349static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 350static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
350{ 351{
351 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 352 struct stv0299_state* state = fe->demodulator_priv;
352 u8 reg0x08; 353 u8 reg0x08;
353 u8 reg0x0c; 354 u8 reg0x0c;
354 355
@@ -385,34 +386,84 @@ static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
385 }; 386 };
386} 387}
387 388
388static int stv0299_send_legacy_dish_cmd(struct dvb_frontend* fe, u32 cmd) 389static inline s32 stv0299_calc_usec_delay (struct timeval lasttime, struct timeval curtime)
389{ 390{
391 return ((curtime.tv_usec < lasttime.tv_usec) ?
392 1000000 - lasttime.tv_usec + curtime.tv_usec :
393 curtime.tv_usec - lasttime.tv_usec);
394}
395
396static void stv0299_sleep_until (struct timeval *waketime, u32 add_usec)
397{
398 struct timeval lasttime;
399 s32 delta, newdelta;
400
401 waketime->tv_usec += add_usec;
402 if (waketime->tv_usec >= 1000000) {
403 waketime->tv_usec -= 1000000;
404 waketime->tv_sec++;
405 }
406
407 do_gettimeofday (&lasttime);
408 delta = stv0299_calc_usec_delay (lasttime, *waketime);
409 if (delta > 2500) {
410 msleep ((delta - 1500) / 1000);
411 do_gettimeofday (&lasttime);
412 newdelta = stv0299_calc_usec_delay (lasttime, *waketime);
413 delta = (newdelta > delta) ? 0 : newdelta;
414 }
415 if (delta > 0)
416 udelay (delta);
417}
418
419static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, u32 cmd)
420{
421 struct stv0299_state* state = fe->demodulator_priv;
422 u8 reg0x08;
423 u8 reg0x0c;
424 u8 lv_mask = 0x40;
390 u8 last = 1; 425 u8 last = 1;
391 int i; 426 int i;
427 struct timeval nexttime;
428 struct timeval tv[10];
392 429
393 /* reset voltage at the end 430 reg0x08 = stv0299_readreg (state, 0x08);
394 if((0x50 & stv0299_readreg (i2c, 0x0c)) == 0x50) 431 reg0x0c = stv0299_readreg (state, 0x0c);
395 cmd |= 0x80; 432 reg0x0c &= 0x0f;
396 else 433 stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6));
397 cmd &= 0x7F; 434 if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0)
398 */ 435 lv_mask = 0x10;
399 436
400 cmd = cmd << 1; 437 cmd = cmd << 1;
401 dprintk("%s switch command: 0x%04x\n",__FUNCTION__, cmd); 438 if (debug_legacy_dish_switch)
439 printk ("%s switch command: 0x%04x\n",__FUNCTION__, cmd);
440
441 do_gettimeofday (&nexttime);
442 if (debug_legacy_dish_switch)
443 memcpy (&tv[0], &nexttime, sizeof (struct timeval));
444 stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */
402 445
403 stv0299_set_voltage(fe,SEC_VOLTAGE_18); 446 stv0299_sleep_until (&nexttime, 32000);
404 msleep(32);
405 447
406 for (i=0; i<9; i++) { 448 for (i=0; i<9; i++) {
449 if (debug_legacy_dish_switch)
450 do_gettimeofday (&tv[i+1]);
407 if((cmd & 0x01) != last) { 451 if((cmd & 0x01) != last) {
408 stv0299_set_voltage(fe, last ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18); 452 /* set voltage to (last ? 13V : 18V) */
453 stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50));
409 last = (last) ? 0 : 1; 454 last = (last) ? 0 : 1;
410 } 455 }
411 456
412 cmd = cmd >> 1; 457 cmd = cmd >> 1;
413 458
414 if (i != 8) 459 if (i != 8)
415 msleep(8); 460 stv0299_sleep_until (&nexttime, 8000);
461 }
462 if (debug_legacy_dish_switch) {
463 printk ("%s(%d): switch delay (should be 32k followed by all 8k\n",
464 __FUNCTION__, fe->dvb->num);
465 for (i=1; i < 10; i++)
466 printk ("%d: %d\n", i, stv0299_calc_usec_delay (tv[i-1] , tv[i]));
416 } 467 }
417 468
418 return 0; 469 return 0;
@@ -420,7 +471,7 @@ static int stv0299_send_legacy_dish_cmd(struct dvb_frontend* fe, u32 cmd)
420 471
421static int stv0299_init (struct dvb_frontend* fe) 472static int stv0299_init (struct dvb_frontend* fe)
422{ 473{
423 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 474 struct stv0299_state* state = fe->demodulator_priv;
424 int i; 475 int i;
425 476
426 dprintk("stv0299: init chip\n"); 477 dprintk("stv0299: init chip\n");
@@ -439,7 +490,7 @@ static int stv0299_init (struct dvb_frontend* fe)
439 490
440static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status) 491static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status)
441{ 492{
442 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 493 struct stv0299_state* state = fe->demodulator_priv;
443 494
444 u8 signal = 0xff - stv0299_readreg (state, 0x18); 495 u8 signal = 0xff - stv0299_readreg (state, 0x18);
445 u8 sync = stv0299_readreg (state, 0x1b); 496 u8 sync = stv0299_readreg (state, 0x1b);
@@ -467,7 +518,7 @@ static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status)
467 518
468static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber) 519static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber)
469{ 520{
470 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 521 struct stv0299_state* state = fe->demodulator_priv;
471 522
472 if (state->errmode != STATUS_BER) return 0; 523 if (state->errmode != STATUS_BER) return 0;
473 *ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e); 524 *ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
@@ -477,7 +528,7 @@ static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber)
477 528
478static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength) 529static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength)
479{ 530{
480 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 531 struct stv0299_state* state = fe->demodulator_priv;
481 532
482 s32 signal = 0xffff - ((stv0299_readreg (state, 0x18) << 8) 533 s32 signal = 0xffff - ((stv0299_readreg (state, 0x18) << 8)
483 | stv0299_readreg (state, 0x19)); 534 | stv0299_readreg (state, 0x19));
@@ -494,7 +545,7 @@ static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength)
494 545
495static int stv0299_read_snr(struct dvb_frontend* fe, u16* snr) 546static int stv0299_read_snr(struct dvb_frontend* fe, u16* snr)
496{ 547{
497 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 548 struct stv0299_state* state = fe->demodulator_priv;
498 549
499 s32 xsnr = 0xffff - ((stv0299_readreg (state, 0x24) << 8) 550 s32 xsnr = 0xffff - ((stv0299_readreg (state, 0x24) << 8)
500 | stv0299_readreg (state, 0x25)); 551 | stv0299_readreg (state, 0x25));
@@ -506,7 +557,7 @@ static int stv0299_read_snr(struct dvb_frontend* fe, u16* snr)
506 557
507static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 558static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
508{ 559{
509 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 560 struct stv0299_state* state = fe->demodulator_priv;
510 561
511 if (state->errmode != STATUS_UCBLOCKS) *ucblocks = 0; 562 if (state->errmode != STATUS_UCBLOCKS) *ucblocks = 0;
512 else *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e); 563 else *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
@@ -516,7 +567,7 @@ static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
516 567
517static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p) 568static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p)
518{ 569{
519 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 570 struct stv0299_state* state = fe->demodulator_priv;
520 int invval = 0; 571 int invval = 0;
521 572
522 dprintk ("%s : FE_SET_FRONTEND\n", __FUNCTION__); 573 dprintk ("%s : FE_SET_FRONTEND\n", __FUNCTION__);
@@ -584,7 +635,7 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
584 635
585static int stv0299_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p) 636static int stv0299_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p)
586{ 637{
587 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 638 struct stv0299_state* state = fe->demodulator_priv;
588 s32 derot_freq; 639 s32 derot_freq;
589 int invval; 640 int invval;
590 641
@@ -609,7 +660,7 @@ static int stv0299_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
609 660
610static int stv0299_sleep(struct dvb_frontend* fe) 661static int stv0299_sleep(struct dvb_frontend* fe)
611{ 662{
612 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 663 struct stv0299_state* state = fe->demodulator_priv;
613 664
614 stv0299_writeregI(state, 0x02, 0x80); 665 stv0299_writeregI(state, 0x02, 0x80);
615 state->initialised = 0; 666 state->initialised = 0;
@@ -619,7 +670,7 @@ static int stv0299_sleep(struct dvb_frontend* fe)
619 670
620static int stv0299_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) 671static int stv0299_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
621{ 672{
622 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 673 struct stv0299_state* state = fe->demodulator_priv;
623 674
624 fesettings->min_delay_ms = state->config->min_delay_ms; 675 fesettings->min_delay_ms = state->config->min_delay_ms;
625 if (fesettings->parameters.u.qpsk.symbol_rate < 10000000) { 676 if (fesettings->parameters.u.qpsk.symbol_rate < 10000000) {
@@ -634,7 +685,7 @@ static int stv0299_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronten
634 685
635static void stv0299_release(struct dvb_frontend* fe) 686static void stv0299_release(struct dvb_frontend* fe)
636{ 687{
637 struct stv0299_state* state = (struct stv0299_state*) fe->demodulator_priv; 688 struct stv0299_state* state = fe->demodulator_priv;
638 kfree(state); 689 kfree(state);
639} 690}
640 691
@@ -647,7 +698,7 @@ struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
647 int id; 698 int id;
648 699
649 /* allocate memory for the internal state */ 700 /* allocate memory for the internal state */
650 state = (struct stv0299_state*) kmalloc(sizeof(struct stv0299_state), GFP_KERNEL); 701 state = kmalloc(sizeof(struct stv0299_state), GFP_KERNEL);
651 if (state == NULL) goto error; 702 if (state == NULL) goto error;
652 703
653 /* setup the state */ 704 /* setup the state */
@@ -719,6 +770,9 @@ static struct dvb_frontend_ops stv0299_ops = {
719 .dishnetwork_send_legacy_command = stv0299_send_legacy_dish_cmd, 770 .dishnetwork_send_legacy_command = stv0299_send_legacy_dish_cmd,
720}; 771};
721 772
773module_param(debug_legacy_dish_switch, int, 0444);
774MODULE_PARM_DESC(debug_legacy_dish_switch, "Enable timing analysis for Dish Network legacy switches");
775
722module_param(debug, int, 0644); 776module_param(debug, int, 0644);
723MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); 777MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
724 778
diff --git a/drivers/media/dvb/frontends/tda10021.c b/drivers/media/dvb/frontends/tda10021.c
index 4e40d95ee95d..87d5f4d8790f 100644
--- a/drivers/media/dvb/frontends/tda10021.c
+++ b/drivers/media/dvb/frontends/tda10021.c
@@ -205,7 +205,7 @@ static int tda10021_set_symbolrate (struct tda10021_state* state, u32 symbolrate
205 205
206static int tda10021_init (struct dvb_frontend *fe) 206static int tda10021_init (struct dvb_frontend *fe)
207{ 207{
208 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 208 struct tda10021_state* state = fe->demodulator_priv;
209 int i; 209 int i;
210 210
211 dprintk("DVB: TDA10021(%d): init chip\n", fe->adapter->num); 211 dprintk("DVB: TDA10021(%d): init chip\n", fe->adapter->num);
@@ -238,7 +238,7 @@ static int tda10021_init (struct dvb_frontend *fe)
238static int tda10021_set_parameters (struct dvb_frontend *fe, 238static int tda10021_set_parameters (struct dvb_frontend *fe,
239 struct dvb_frontend_parameters *p) 239 struct dvb_frontend_parameters *p)
240{ 240{
241 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 241 struct tda10021_state* state = fe->demodulator_priv;
242 242
243 //table for QAM4-QAM256 ready QAM4 QAM16 QAM32 QAM64 QAM128 QAM256 243 //table for QAM4-QAM256 ready QAM4 QAM16 QAM32 QAM64 QAM128 QAM256
244 //CONF 244 //CONF
@@ -278,7 +278,7 @@ static int tda10021_set_parameters (struct dvb_frontend *fe,
278 278
279static int tda10021_read_status(struct dvb_frontend* fe, fe_status_t* status) 279static int tda10021_read_status(struct dvb_frontend* fe, fe_status_t* status)
280{ 280{
281 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 281 struct tda10021_state* state = fe->demodulator_priv;
282 int sync; 282 int sync;
283 283
284 *status = 0; 284 *status = 0;
@@ -303,7 +303,7 @@ static int tda10021_read_status(struct dvb_frontend* fe, fe_status_t* status)
303 303
304static int tda10021_read_ber(struct dvb_frontend* fe, u32* ber) 304static int tda10021_read_ber(struct dvb_frontend* fe, u32* ber)
305{ 305{
306 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 306 struct tda10021_state* state = fe->demodulator_priv;
307 307
308 u32 _ber = tda10021_readreg(state, 0x14) | 308 u32 _ber = tda10021_readreg(state, 0x14) |
309 (tda10021_readreg(state, 0x15) << 8) | 309 (tda10021_readreg(state, 0x15) << 8) |
@@ -315,7 +315,7 @@ static int tda10021_read_ber(struct dvb_frontend* fe, u32* ber)
315 315
316static int tda10021_read_signal_strength(struct dvb_frontend* fe, u16* strength) 316static int tda10021_read_signal_strength(struct dvb_frontend* fe, u16* strength)
317{ 317{
318 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 318 struct tda10021_state* state = fe->demodulator_priv;
319 319
320 u8 gain = tda10021_readreg(state, 0x17); 320 u8 gain = tda10021_readreg(state, 0x17);
321 *strength = (gain << 8) | gain; 321 *strength = (gain << 8) | gain;
@@ -325,7 +325,7 @@ static int tda10021_read_signal_strength(struct dvb_frontend* fe, u16* strength)
325 325
326static int tda10021_read_snr(struct dvb_frontend* fe, u16* snr) 326static int tda10021_read_snr(struct dvb_frontend* fe, u16* snr)
327{ 327{
328 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 328 struct tda10021_state* state = fe->demodulator_priv;
329 329
330 u8 quality = ~tda10021_readreg(state, 0x18); 330 u8 quality = ~tda10021_readreg(state, 0x18);
331 *snr = (quality << 8) | quality; 331 *snr = (quality << 8) | quality;
@@ -335,7 +335,7 @@ static int tda10021_read_snr(struct dvb_frontend* fe, u16* snr)
335 335
336static int tda10021_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 336static int tda10021_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
337{ 337{
338 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 338 struct tda10021_state* state = fe->demodulator_priv;
339 339
340 *ucblocks = tda10021_readreg (state, 0x13) & 0x7f; 340 *ucblocks = tda10021_readreg (state, 0x13) & 0x7f;
341 if (*ucblocks == 0x7f) 341 if (*ucblocks == 0x7f)
@@ -350,7 +350,7 @@ static int tda10021_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
350 350
351static int tda10021_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 351static int tda10021_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
352{ 352{
353 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 353 struct tda10021_state* state = fe->demodulator_priv;
354 int sync; 354 int sync;
355 s8 afc = 0; 355 s8 afc = 0;
356 356
@@ -378,7 +378,7 @@ static int tda10021_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_pa
378 378
379static int tda10021_sleep(struct dvb_frontend* fe) 379static int tda10021_sleep(struct dvb_frontend* fe)
380{ 380{
381 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 381 struct tda10021_state* state = fe->demodulator_priv;
382 382
383 tda10021_writereg (state, 0x1b, 0x02); /* pdown ADC */ 383 tda10021_writereg (state, 0x1b, 0x02); /* pdown ADC */
384 tda10021_writereg (state, 0x00, 0x80); /* standby */ 384 tda10021_writereg (state, 0x00, 0x80); /* standby */
@@ -388,7 +388,7 @@ static int tda10021_sleep(struct dvb_frontend* fe)
388 388
389static void tda10021_release(struct dvb_frontend* fe) 389static void tda10021_release(struct dvb_frontend* fe)
390{ 390{
391 struct tda10021_state* state = (struct tda10021_state*) fe->demodulator_priv; 391 struct tda10021_state* state = fe->demodulator_priv;
392 kfree(state); 392 kfree(state);
393} 393}
394 394
@@ -401,7 +401,7 @@ struct dvb_frontend* tda10021_attach(const struct tda10021_config* config,
401 struct tda10021_state* state = NULL; 401 struct tda10021_state* state = NULL;
402 402
403 /* allocate memory for the internal state */ 403 /* allocate memory for the internal state */
404 state = (struct tda10021_state*) kmalloc(sizeof(struct tda10021_state), GFP_KERNEL); 404 state = kmalloc(sizeof(struct tda10021_state), GFP_KERNEL);
405 if (state == NULL) goto error; 405 if (state == NULL) goto error;
406 406
407 /* setup the state */ 407 /* setup the state */
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 687ad9cf3384..0beb370792ae 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -35,9 +35,10 @@
35#include "dvb_frontend.h" 35#include "dvb_frontend.h"
36#include "tda1004x.h" 36#include "tda1004x.h"
37 37
38#define TDA1004X_DEMOD_TDA10045 0 38enum tda1004x_demod {
39#define TDA1004X_DEMOD_TDA10046 1 39 TDA1004X_DEMOD_TDA10045,
40 40 TDA1004X_DEMOD_TDA10046,
41};
41 42
42struct tda1004x_state { 43struct tda1004x_state {
43 struct i2c_adapter* i2c; 44 struct i2c_adapter* i2c;
@@ -46,8 +47,9 @@ struct tda1004x_state {
46 struct dvb_frontend frontend; 47 struct dvb_frontend frontend;
47 48
48 /* private demod data */ 49 /* private demod data */
49 u8 initialised:1; 50 u8 initialised;
50 u8 demod_type; 51 enum tda1004x_demod demod_type;
52 u8 fw_version;
51}; 53};
52 54
53 55
@@ -139,7 +141,7 @@ static int tda1004x_write_byteI(struct tda1004x_state *state, int reg, int data)
139{ 141{
140 int ret; 142 int ret;
141 u8 buf[] = { reg, data }; 143 u8 buf[] = { reg, data };
142 struct i2c_msg msg = { .addr=0, .flags=0, .buf=buf, .len=2 }; 144 struct i2c_msg msg = { .flags = 0, .buf = buf, .len = 2 };
143 145
144 dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__, reg, data); 146 dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__, reg, data);
145 147
@@ -160,8 +162,8 @@ static int tda1004x_read_byte(struct tda1004x_state *state, int reg)
160 int ret; 162 int ret;
161 u8 b0[] = { reg }; 163 u8 b0[] = { reg };
162 u8 b1[] = { 0 }; 164 u8 b1[] = { 0 };
163 struct i2c_msg msg[] = {{ .addr=0, .flags=0, .buf=b0, .len=1}, 165 struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
164 { .addr=0, .flags=I2C_M_RD, .buf=b1, .len = 1}}; 166 { .flags = I2C_M_RD, .buf = b1, .len = 1 }};
165 167
166 dprintk("%s: reg=0x%x\n", __FUNCTION__, reg); 168 dprintk("%s: reg=0x%x\n", __FUNCTION__, reg);
167 169
@@ -294,7 +296,7 @@ static int tda1004x_do_upload(struct tda1004x_state *state,
294 u8 dspCodeCounterReg, u8 dspCodeInReg) 296 u8 dspCodeCounterReg, u8 dspCodeInReg)
295{ 297{
296 u8 buf[65]; 298 u8 buf[65];
297 struct i2c_msg fw_msg = {.addr = 0,.flags = 0,.buf = buf,.len = 0 }; 299 struct i2c_msg fw_msg = { .flags = 0, .buf = buf, .len = 0 };
298 int tx_size; 300 int tx_size;
299 int pos = 0; 301 int pos = 0;
300 302
@@ -304,12 +306,10 @@ static int tda1004x_do_upload(struct tda1004x_state *state,
304 306
305 buf[0] = dspCodeInReg; 307 buf[0] = dspCodeInReg;
306 while (pos != len) { 308 while (pos != len) {
307
308 // work out how much to send this time 309 // work out how much to send this time
309 tx_size = len - pos; 310 tx_size = len - pos;
310 if (tx_size > 0x10) { 311 if (tx_size > 0x10)
311 tx_size = 0x10; 312 tx_size = 0x10;
312 }
313 313
314 // send the chunk 314 // send the chunk
315 memcpy(buf + 1, mem + pos, tx_size); 315 memcpy(buf + 1, mem + pos, tx_size);
@@ -322,6 +322,7 @@ static int tda1004x_do_upload(struct tda1004x_state *state,
322 322
323 dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos); 323 dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos);
324 } 324 }
325
325 return 0; 326 return 0;
326} 327}
327 328
@@ -335,9 +336,8 @@ static int tda1004x_check_upload_ok(struct tda1004x_state *state, u8 dspVersion)
335 336
336 data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1); 337 data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1);
337 data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2); 338 data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2);
338 if (data1 != 0x67 || data2 != dspVersion) { 339 if ((data1 != 0x67) || (data2 != dspVersion))
339 return -EIO; 340 return -EIO;
340 }
341 341
342 return 0; 342 return 0;
343} 343}
@@ -348,9 +348,9 @@ static int tda10045_fwupload(struct dvb_frontend* fe)
348 int ret; 348 int ret;
349 const struct firmware *fw; 349 const struct firmware *fw;
350 350
351
352 /* don't re-upload unless necessary */ 351 /* don't re-upload unless necessary */
353 if (tda1004x_check_upload_ok(state, 0x2c) == 0) return 0; 352 if (tda1004x_check_upload_ok(state, 0x2c) == 0)
353 return 0;
354 354
355 /* request the firmware, this will block until someone uploads it */ 355 /* request the firmware, this will block until someone uploads it */
356 printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE); 356 printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE);
@@ -381,6 +381,25 @@ static int tda10045_fwupload(struct dvb_frontend* fe)
381 return tda1004x_check_upload_ok(state, 0x2c); 381 return tda1004x_check_upload_ok(state, 0x2c);
382} 382}
383 383
384static int tda10046_get_fw_version(struct tda1004x_state *state,
385 const struct firmware *fw)
386{
387 const unsigned char pattern[] = { 0x67, 0x00, 0x50, 0x62, 0x5e, 0x18, 0x67 };
388 unsigned int i;
389
390 /* area guessed from firmware v20, v21 and v25 */
391 for (i = 0x660; i < 0x700; i++) {
392 if (!memcmp(&fw->data[i], pattern, sizeof(pattern))) {
393 state->fw_version = fw->data[i + sizeof(pattern)];
394 printk(KERN_INFO "tda1004x: using firmware v%02x\n",
395 state->fw_version);
396 return 0;
397 }
398 }
399
400 return -EINVAL;
401}
402
384static int tda10046_fwupload(struct dvb_frontend* fe) 403static int tda10046_fwupload(struct dvb_frontend* fe)
385{ 404{
386 struct tda1004x_state* state = fe->demodulator_priv; 405 struct tda1004x_state* state = fe->demodulator_priv;
@@ -394,7 +413,8 @@ static int tda10046_fwupload(struct dvb_frontend* fe)
394 msleep(100); 413 msleep(100);
395 414
396 /* don't re-upload unless necessary */ 415 /* don't re-upload unless necessary */
397 if (tda1004x_check_upload_ok(state, 0x20) == 0) return 0; 416 if (tda1004x_check_upload_ok(state, state->fw_version) == 0)
417 return 0;
398 418
399 /* request the firmware, this will block until someone uploads it */ 419 /* request the firmware, this will block until someone uploads it */
400 printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10046_DEFAULT_FIRMWARE); 420 printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10046_DEFAULT_FIRMWARE);
@@ -404,9 +424,20 @@ static int tda10046_fwupload(struct dvb_frontend* fe)
404 return ret; 424 return ret;
405 } 425 }
406 426
427 if (fw->size < 24478) { /* size of firmware v20, which is the smallest of v20, v21 and v25 */
428 printk("tda1004x: firmware file seems to be too small (%d bytes)\n", fw->size);
429 return -EINVAL;
430 }
431
432 ret = tda10046_get_fw_version(state, fw);
433 if (ret < 0) {
434 printk("tda1004x: unable to find firmware version\n");
435 return ret;
436 }
437
407 /* set parameters */ 438 /* set parameters */
408 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); 439 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10);
409 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 0); 440 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, state->config->n_i2c);
410 tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99); 441 tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99);
411 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4); 442 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4);
412 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c); 443 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c);
@@ -419,7 +450,7 @@ static int tda10046_fwupload(struct dvb_frontend* fe)
419 450
420 /* wait for DSP to initialise */ 451 /* wait for DSP to initialise */
421 timeout = jiffies + HZ; 452 timeout = jiffies + HZ;
422 while(!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) { 453 while (!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) {
423 if (time_after(jiffies, timeout)) { 454 if (time_after(jiffies, timeout)) {
424 printk("tda1004x: DSP failed to initialised.\n"); 455 printk("tda1004x: DSP failed to initialised.\n");
425 return -EIO; 456 return -EIO;
@@ -427,7 +458,7 @@ static int tda10046_fwupload(struct dvb_frontend* fe)
427 msleep(1); 458 msleep(1);
428 } 459 }
429 460
430 return tda1004x_check_upload_ok(state, 0x20); 461 return tda1004x_check_upload_ok(state, state->fw_version);
431} 462}
432 463
433static int tda1004x_encode_fec(int fec) 464static int tda1004x_encode_fec(int fec)
@@ -483,7 +514,8 @@ static int tda10045_init(struct dvb_frontend* fe)
483 514
484 dprintk("%s\n", __FUNCTION__); 515 dprintk("%s\n", __FUNCTION__);
485 516
486 if (state->initialised) return 0; 517 if (state->initialised)
518 return 0;
487 519
488 if (tda10045_fwupload(fe)) { 520 if (tda10045_fwupload(fe)) {
489 printk("tda1004x: firmware upload failed\n"); 521 printk("tda1004x: firmware upload failed\n");
@@ -523,7 +555,8 @@ static int tda10046_init(struct dvb_frontend* fe)
523 struct tda1004x_state* state = fe->demodulator_priv; 555 struct tda1004x_state* state = fe->demodulator_priv;
524 dprintk("%s\n", __FUNCTION__); 556 dprintk("%s\n", __FUNCTION__);
525 557
526 if (state->initialised) return 0; 558 if (state->initialised)
559 return 0;
527 560
528 if (tda10046_fwupload(fe)) { 561 if (tda10046_fwupload(fe)) {
529 printk("tda1004x: firmware upload failed\n"); 562 printk("tda1004x: firmware upload failed\n");
@@ -545,7 +578,7 @@ static int tda10046_init(struct dvb_frontend* fe)
545 tda1004x_write_mask(state, TDA1004X_AUTO, 8, 0); // select HP stream 578 tda1004x_write_mask(state, TDA1004X_AUTO, 8, 0); // select HP stream
546 tda1004x_write_mask(state, TDA1004X_CONFC1, 0x80, 0); // disable pulse killer 579 tda1004x_write_mask(state, TDA1004X_CONFC1, 0x80, 0); // disable pulse killer
547 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); // PLL M = 10 580 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); // PLL M = 10
548 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 0); // PLL P = N = 0 581 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, state->config->n_i2c); // PLL P = N = 0
549 tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99); // FREQOFFS = 99 582 tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99); // FREQOFFS = 99
550 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4); // } PHY2 = -11221 583 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4); // } PHY2 = -11221
551 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c); // } 584 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c); // }
@@ -621,12 +654,14 @@ static int tda1004x_set_fe(struct dvb_frontend* fe,
621 654
622 // set HP FEC 655 // set HP FEC
623 tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_HP); 656 tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_HP);
624 if (tmp < 0) return tmp; 657 if (tmp < 0)
658 return tmp;
625 tda1004x_write_mask(state, TDA1004X_IN_CONF2, 7, tmp); 659 tda1004x_write_mask(state, TDA1004X_IN_CONF2, 7, tmp);
626 660
627 // set LP FEC 661 // set LP FEC
628 tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_LP); 662 tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_LP);
629 if (tmp < 0) return tmp; 663 if (tmp < 0)
664 return tmp;
630 tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x38, tmp << 3); 665 tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x38, tmp << 3);
631 666
632 // set constellation 667 // set constellation
@@ -671,7 +706,7 @@ static int tda1004x_set_fe(struct dvb_frontend* fe,
671 } 706 }
672 707
673 // set bandwidth 708 // set bandwidth
674 switch(state->demod_type) { 709 switch (state->demod_type) {
675 case TDA1004X_DEMOD_TDA10045: 710 case TDA1004X_DEMOD_TDA10045:
676 tda10045h_set_bandwidth(state, fe_params->u.ofdm.bandwidth); 711 tda10045h_set_bandwidth(state, fe_params->u.ofdm.bandwidth);
677 break; 712 break;
@@ -683,7 +718,8 @@ static int tda1004x_set_fe(struct dvb_frontend* fe,
683 718
684 // set inversion 719 // set inversion
685 inversion = fe_params->inversion; 720 inversion = fe_params->inversion;
686 if (state->config->invert) inversion = inversion ? INVERSION_OFF : INVERSION_ON; 721 if (state->config->invert)
722 inversion = inversion ? INVERSION_OFF : INVERSION_ON;
687 switch (inversion) { 723 switch (inversion) {
688 case INVERSION_OFF: 724 case INVERSION_OFF:
689 tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0); 725 tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0);
@@ -750,19 +786,19 @@ static int tda1004x_set_fe(struct dvb_frontend* fe,
750 } 786 }
751 787
752 // start the lock 788 // start the lock
753 switch(state->demod_type) { 789 switch (state->demod_type) {
754 case TDA1004X_DEMOD_TDA10045: 790 case TDA1004X_DEMOD_TDA10045:
755 tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8); 791 tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8);
756 tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0); 792 tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0);
757 msleep(10);
758 break; 793 break;
759 794
760 case TDA1004X_DEMOD_TDA10046: 795 case TDA1004X_DEMOD_TDA10046:
761 tda1004x_write_mask(state, TDA1004X_AUTO, 0x40, 0x40); 796 tda1004x_write_mask(state, TDA1004X_AUTO, 0x40, 0x40);
762 msleep(10);
763 break; 797 break;
764 } 798 }
765 799
800 msleep(10);
801
766 return 0; 802 return 0;
767} 803}
768 804
@@ -773,13 +809,13 @@ static int tda1004x_get_fe(struct dvb_frontend* fe, struct dvb_frontend_paramete
773 809
774 // inversion status 810 // inversion status
775 fe_params->inversion = INVERSION_OFF; 811 fe_params->inversion = INVERSION_OFF;
776 if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20) { 812 if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20)
777 fe_params->inversion = INVERSION_ON; 813 fe_params->inversion = INVERSION_ON;
778 } 814 if (state->config->invert)
779 if (state->config->invert) fe_params->inversion = fe_params->inversion ? INVERSION_OFF : INVERSION_ON; 815 fe_params->inversion = fe_params->inversion ? INVERSION_OFF : INVERSION_ON;
780 816
781 // bandwidth 817 // bandwidth
782 switch(state->demod_type) { 818 switch (state->demod_type) {
783 case TDA1004X_DEMOD_TDA10045: 819 case TDA1004X_DEMOD_TDA10045:
784 switch (tda1004x_read_byte(state, TDA10045H_WREF_LSB)) { 820 switch (tda1004x_read_byte(state, TDA10045H_WREF_LSB)) {
785 case 0x14: 821 case 0x14:
@@ -830,9 +866,8 @@ static int tda1004x_get_fe(struct dvb_frontend* fe, struct dvb_frontend_paramete
830 866
831 // transmission mode 867 // transmission mode
832 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; 868 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
833 if (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x10) { 869 if (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x10)
834 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; 870 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
835 }
836 871
837 // guard interval 872 // guard interval
838 switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x0c) >> 2) { 873 switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x0c) >> 2) {
@@ -880,30 +915,33 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status
880 915
881 // read status 916 // read status
882 status = tda1004x_read_byte(state, TDA1004X_STATUS_CD); 917 status = tda1004x_read_byte(state, TDA1004X_STATUS_CD);
883 if (status == -1) { 918 if (status == -1)
884 return -EIO; 919 return -EIO;
885 }
886 920
887 // decode 921 // decode
888 *fe_status = 0; 922 *fe_status = 0;
889 if (status & 4) *fe_status |= FE_HAS_SIGNAL; 923 if (status & 4)
890 if (status & 2) *fe_status |= FE_HAS_CARRIER; 924 *fe_status |= FE_HAS_SIGNAL;
891 if (status & 8) *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 925 if (status & 2)
926 *fe_status |= FE_HAS_CARRIER;
927 if (status & 8)
928 *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
892 929
893 // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi 930 // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi
894 // is getting anything valid 931 // is getting anything valid
895 if (!(*fe_status & FE_HAS_VITERBI)) { 932 if (!(*fe_status & FE_HAS_VITERBI)) {
896 // read the CBER 933 // read the CBER
897 cber = tda1004x_read_byte(state, TDA1004X_CBER_LSB); 934 cber = tda1004x_read_byte(state, TDA1004X_CBER_LSB);
898 if (cber == -1) return -EIO; 935 if (cber == -1)
936 return -EIO;
899 status = tda1004x_read_byte(state, TDA1004X_CBER_MSB); 937 status = tda1004x_read_byte(state, TDA1004X_CBER_MSB);
900 if (status == -1) return -EIO; 938 if (status == -1)
939 return -EIO;
901 cber |= (status << 8); 940 cber |= (status << 8);
902 tda1004x_read_byte(state, TDA1004X_CBER_RESET); 941 tda1004x_read_byte(state, TDA1004X_CBER_RESET);
903 942
904 if (cber != 65535) { 943 if (cber != 65535)
905 *fe_status |= FE_HAS_VITERBI; 944 *fe_status |= FE_HAS_VITERBI;
906 }
907 } 945 }
908 946
909 // if we DO have some valid VITERBI output, but don't already have SYNC 947 // if we DO have some valid VITERBI output, but don't already have SYNC
@@ -911,20 +949,22 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status
911 if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status & FE_HAS_SYNC))) { 949 if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status & FE_HAS_SYNC))) {
912 // read the VBER 950 // read the VBER
913 vber = tda1004x_read_byte(state, TDA1004X_VBER_LSB); 951 vber = tda1004x_read_byte(state, TDA1004X_VBER_LSB);
914 if (vber == -1) return -EIO; 952 if (vber == -1)
953 return -EIO;
915 status = tda1004x_read_byte(state, TDA1004X_VBER_MID); 954 status = tda1004x_read_byte(state, TDA1004X_VBER_MID);
916 if (status == -1) return -EIO; 955 if (status == -1)
956 return -EIO;
917 vber |= (status << 8); 957 vber |= (status << 8);
918 status = tda1004x_read_byte(state, TDA1004X_VBER_MSB); 958 status = tda1004x_read_byte(state, TDA1004X_VBER_MSB);
919 if (status == -1) return -EIO; 959 if (status == -1)
960 return -EIO;
920 vber |= ((status << 16) & 0x0f); 961 vber |= ((status << 16) & 0x0f);
921 tda1004x_read_byte(state, TDA1004X_CVBER_LUT); 962 tda1004x_read_byte(state, TDA1004X_CVBER_LUT);
922 963
923 // if RS has passed some valid TS packets, then we must be 964 // if RS has passed some valid TS packets, then we must be
924 // getting some SYNC bytes 965 // getting some SYNC bytes
925 if (vber < 16632) { 966 if (vber < 16632)
926 *fe_status |= FE_HAS_SYNC; 967 *fe_status |= FE_HAS_SYNC;
927 }
928 } 968 }
929 969
930 // success 970 // success
@@ -941,7 +981,7 @@ static int tda1004x_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
941 dprintk("%s\n", __FUNCTION__); 981 dprintk("%s\n", __FUNCTION__);
942 982
943 // determine the register to use 983 // determine the register to use
944 switch(state->demod_type) { 984 switch (state->demod_type) {
945 case TDA1004X_DEMOD_TDA10045: 985 case TDA1004X_DEMOD_TDA10045:
946 reg = TDA10045H_S_AGC; 986 reg = TDA10045H_S_AGC;
947 break; 987 break;
@@ -972,9 +1012,8 @@ static int tda1004x_read_snr(struct dvb_frontend* fe, u16 * snr)
972 tmp = tda1004x_read_byte(state, TDA1004X_SNR); 1012 tmp = tda1004x_read_byte(state, TDA1004X_SNR);
973 if (tmp < 0) 1013 if (tmp < 0)
974 return -EIO; 1014 return -EIO;
975 if (tmp) { 1015 if (tmp)
976 tmp = 255 - tmp; 1016 tmp = 255 - tmp;
977 }
978 1017
979 *snr = ((tmp << 8) | tmp); 1018 *snr = ((tmp << 8) | tmp);
980 dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr); 1019 dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr);
@@ -1009,11 +1048,11 @@ static int tda1004x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
1009 break; 1048 break;
1010 } 1049 }
1011 1050
1012 if (tmp != 0x7f) { 1051 if (tmp != 0x7f)
1013 *ucblocks = tmp; 1052 *ucblocks = tmp;
1014 } else { 1053 else
1015 *ucblocks = 0xffffffff; 1054 *ucblocks = 0xffffffff;
1016 } 1055
1017 dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks); 1056 dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks);
1018 return 0; 1057 return 0;
1019} 1058}
@@ -1027,10 +1066,12 @@ static int tda1004x_read_ber(struct dvb_frontend* fe, u32* ber)
1027 1066
1028 // read it in 1067 // read it in
1029 tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB); 1068 tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB);
1030 if (tmp < 0) return -EIO; 1069 if (tmp < 0)
1070 return -EIO;
1031 *ber = tmp << 1; 1071 *ber = tmp << 1;
1032 tmp = tda1004x_read_byte(state, TDA1004X_CBER_MSB); 1072 tmp = tda1004x_read_byte(state, TDA1004X_CBER_MSB);
1033 if (tmp < 0) return -EIO; 1073 if (tmp < 0)
1074 return -EIO;
1034 *ber |= (tmp << 9); 1075 *ber |= (tmp << 9);
1035 tda1004x_read_byte(state, TDA1004X_CBER_RESET); 1076 tda1004x_read_byte(state, TDA1004X_CBER_RESET);
1036 1077
@@ -1042,7 +1083,7 @@ static int tda1004x_sleep(struct dvb_frontend* fe)
1042{ 1083{
1043 struct tda1004x_state* state = fe->demodulator_priv; 1084 struct tda1004x_state* state = fe->demodulator_priv;
1044 1085
1045 switch(state->demod_type) { 1086 switch (state->demod_type) {
1046 case TDA1004X_DEMOD_TDA10045: 1087 case TDA1004X_DEMOD_TDA10045:
1047 tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0x10); 1088 tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0x10);
1048 break; 1089 break;
@@ -1066,74 +1107,11 @@ static int tda1004x_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronte
1066 1107
1067static void tda1004x_release(struct dvb_frontend* fe) 1108static void tda1004x_release(struct dvb_frontend* fe)
1068{ 1109{
1069 struct tda1004x_state* state = (struct tda1004x_state*) fe->demodulator_priv; 1110 struct tda1004x_state *state = fe->demodulator_priv;
1070 kfree(state);
1071}
1072
1073static struct dvb_frontend_ops tda10045_ops;
1074
1075struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
1076 struct i2c_adapter* i2c)
1077{
1078 struct tda1004x_state* state = NULL;
1079
1080 /* allocate memory for the internal state */
1081 state = (struct tda1004x_state*) kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
1082 if (state == NULL) goto error;
1083
1084 /* setup the state */
1085 state->config = config;
1086 state->i2c = i2c;
1087 memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops));
1088 state->initialised = 0;
1089 state->demod_type = TDA1004X_DEMOD_TDA10045;
1090
1091 /* check if the demod is there */
1092 if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x25) goto error;
1093
1094 /* create dvb_frontend */
1095 state->frontend.ops = &state->ops;
1096 state->frontend.demodulator_priv = state;
1097 return &state->frontend;
1098
1099error:
1100 kfree(state); 1111 kfree(state);
1101 return NULL;
1102}
1103
1104static struct dvb_frontend_ops tda10046_ops;
1105
1106struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
1107 struct i2c_adapter* i2c)
1108{
1109 struct tda1004x_state* state = NULL;
1110
1111 /* allocate memory for the internal state */
1112 state = (struct tda1004x_state*) kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
1113 if (state == NULL) goto error;
1114
1115 /* setup the state */
1116 state->config = config;
1117 state->i2c = i2c;
1118 memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops));
1119 state->initialised = 0;
1120 state->demod_type = TDA1004X_DEMOD_TDA10046;
1121
1122 /* check if the demod is there */
1123 if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) goto error;
1124
1125 /* create dvb_frontend */
1126 state->frontend.ops = &state->ops;
1127 state->frontend.demodulator_priv = state;
1128 return &state->frontend;
1129
1130error:
1131 if (state) kfree(state);
1132 return NULL;
1133} 1112}
1134 1113
1135static struct dvb_frontend_ops tda10045_ops = { 1114static struct dvb_frontend_ops tda10045_ops = {
1136
1137 .info = { 1115 .info = {
1138 .name = "Philips TDA10045H DVB-T", 1116 .name = "Philips TDA10045H DVB-T",
1139 .type = FE_OFDM, 1117 .type = FE_OFDM,
@@ -1163,8 +1141,36 @@ static struct dvb_frontend_ops tda10045_ops = {
1163 .read_ucblocks = tda1004x_read_ucblocks, 1141 .read_ucblocks = tda1004x_read_ucblocks,
1164}; 1142};
1165 1143
1166static struct dvb_frontend_ops tda10046_ops = { 1144struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
1145 struct i2c_adapter* i2c)
1146{
1147 struct tda1004x_state *state;
1148
1149 /* allocate memory for the internal state */
1150 state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
1151 if (!state)
1152 return NULL;
1153
1154 /* setup the state */
1155 state->config = config;
1156 state->i2c = i2c;
1157 memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops));
1158 state->initialised = 0;
1159 state->demod_type = TDA1004X_DEMOD_TDA10045;
1160
1161 /* check if the demod is there */
1162 if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x25) {
1163 kfree(state);
1164 return NULL;
1165 }
1167 1166
1167 /* create dvb_frontend */
1168 state->frontend.ops = &state->ops;
1169 state->frontend.demodulator_priv = state;
1170 return &state->frontend;
1171}
1172
1173static struct dvb_frontend_ops tda10046_ops = {
1168 .info = { 1174 .info = {
1169 .name = "Philips TDA10046H DVB-T", 1175 .name = "Philips TDA10046H DVB-T",
1170 .type = FE_OFDM, 1176 .type = FE_OFDM,
@@ -1194,6 +1200,36 @@ static struct dvb_frontend_ops tda10046_ops = {
1194 .read_ucblocks = tda1004x_read_ucblocks, 1200 .read_ucblocks = tda1004x_read_ucblocks,
1195}; 1201};
1196 1202
1203struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
1204 struct i2c_adapter* i2c)
1205{
1206 struct tda1004x_state *state;
1207
1208 /* allocate memory for the internal state */
1209 state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
1210 if (!state)
1211 return NULL;
1212
1213 /* setup the state */
1214 state->config = config;
1215 state->i2c = i2c;
1216 memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops));
1217 state->initialised = 0;
1218 state->demod_type = TDA1004X_DEMOD_TDA10046;
1219 state->fw_version = 0x20; /* dummy default value */
1220
1221 /* check if the demod is there */
1222 if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) {
1223 kfree(state);
1224 return NULL;
1225 }
1226
1227 /* create dvb_frontend */
1228 state->frontend.ops = &state->ops;
1229 state->frontend.demodulator_priv = state;
1230 return &state->frontend;
1231}
1232
1197module_param(debug, int, 0644); 1233module_param(debug, int, 0644);
1198MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); 1234MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
1199 1235
diff --git a/drivers/media/dvb/frontends/tda1004x.h b/drivers/media/dvb/frontends/tda1004x.h
index e452fc0bad11..c8e1d54ff262 100644
--- a/drivers/media/dvb/frontends/tda1004x.h
+++ b/drivers/media/dvb/frontends/tda1004x.h
@@ -32,10 +32,13 @@ struct tda1004x_config
32 u8 demod_address; 32 u8 demod_address;
33 33
34 /* does the "inversion" need inverted? */ 34 /* does the "inversion" need inverted? */
35 u8 invert:1; 35 u8 invert;
36 36
37 /* Does the OCLK signal need inverted? */ 37 /* Does the OCLK signal need inverted? */
38 u8 invert_oclk:1; 38 u8 invert_oclk;
39
40 /* value of N_I2C of the CONF_PLL3 register */
41 u8 n_i2c;
39 42
40 /* PLL maintenance */ 43 /* PLL maintenance */
41 int (*pll_init)(struct dvb_frontend* fe); 44 int (*pll_init)(struct dvb_frontend* fe);
diff --git a/drivers/media/dvb/frontends/tda8083.c b/drivers/media/dvb/frontends/tda8083.c
index da82e90d6d13..168e013d23bd 100644
--- a/drivers/media/dvb/frontends/tda8083.c
+++ b/drivers/media/dvb/frontends/tda8083.c
@@ -226,7 +226,7 @@ static int tda8083_send_diseqc_burst (struct tda8083_state* state, fe_sec_mini_c
226static int tda8083_send_diseqc_msg (struct dvb_frontend* fe, 226static int tda8083_send_diseqc_msg (struct dvb_frontend* fe,
227 struct dvb_diseqc_master_cmd *m) 227 struct dvb_diseqc_master_cmd *m)
228{ 228{
229 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 229 struct tda8083_state* state = fe->demodulator_priv;
230 int i; 230 int i;
231 231
232 tda8083_writereg (state, 0x29, (m->msg_len - 3) | (1 << 2)); /* enable */ 232 tda8083_writereg (state, 0x29, (m->msg_len - 3) | (1 << 2)); /* enable */
@@ -243,7 +243,7 @@ static int tda8083_send_diseqc_msg (struct dvb_frontend* fe,
243 243
244static int tda8083_read_status(struct dvb_frontend* fe, fe_status_t* status) 244static int tda8083_read_status(struct dvb_frontend* fe, fe_status_t* status)
245{ 245{
246 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 246 struct tda8083_state* state = fe->demodulator_priv;
247 247
248 u8 signal = ~tda8083_readreg (state, 0x01); 248 u8 signal = ~tda8083_readreg (state, 0x01);
249 u8 sync = tda8083_readreg (state, 0x02); 249 u8 sync = tda8083_readreg (state, 0x02);
@@ -270,7 +270,7 @@ static int tda8083_read_status(struct dvb_frontend* fe, fe_status_t* status)
270 270
271static int tda8083_read_signal_strength(struct dvb_frontend* fe, u16* strength) 271static int tda8083_read_signal_strength(struct dvb_frontend* fe, u16* strength)
272{ 272{
273 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 273 struct tda8083_state* state = fe->demodulator_priv;
274 274
275 u8 signal = ~tda8083_readreg (state, 0x01); 275 u8 signal = ~tda8083_readreg (state, 0x01);
276 *strength = (signal << 8) | signal; 276 *strength = (signal << 8) | signal;
@@ -280,7 +280,7 @@ static int tda8083_read_signal_strength(struct dvb_frontend* fe, u16* strength)
280 280
281static int tda8083_read_snr(struct dvb_frontend* fe, u16* snr) 281static int tda8083_read_snr(struct dvb_frontend* fe, u16* snr)
282{ 282{
283 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 283 struct tda8083_state* state = fe->demodulator_priv;
284 284
285 u8 _snr = tda8083_readreg (state, 0x08); 285 u8 _snr = tda8083_readreg (state, 0x08);
286 *snr = (_snr << 8) | _snr; 286 *snr = (_snr << 8) | _snr;
@@ -290,7 +290,7 @@ static int tda8083_read_snr(struct dvb_frontend* fe, u16* snr)
290 290
291static int tda8083_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 291static int tda8083_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
292{ 292{
293 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 293 struct tda8083_state* state = fe->demodulator_priv;
294 294
295 state->config->pll_set(fe, p); 295 state->config->pll_set(fe, p);
296 tda8083_set_inversion (state, p->inversion); 296 tda8083_set_inversion (state, p->inversion);
@@ -305,7 +305,7 @@ static int tda8083_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
305 305
306static int tda8083_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 306static int tda8083_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
307{ 307{
308 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 308 struct tda8083_state* state = fe->demodulator_priv;
309 309
310 /* FIXME: get symbolrate & frequency offset...*/ 310 /* FIXME: get symbolrate & frequency offset...*/
311 /*p->frequency = ???;*/ 311 /*p->frequency = ???;*/
@@ -319,7 +319,7 @@ static int tda8083_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
319 319
320static int tda8083_sleep(struct dvb_frontend* fe) 320static int tda8083_sleep(struct dvb_frontend* fe)
321{ 321{
322 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 322 struct tda8083_state* state = fe->demodulator_priv;
323 323
324 tda8083_writereg (state, 0x00, 0x02); 324 tda8083_writereg (state, 0x00, 0x02);
325 return 0; 325 return 0;
@@ -327,7 +327,7 @@ static int tda8083_sleep(struct dvb_frontend* fe)
327 327
328static int tda8083_init(struct dvb_frontend* fe) 328static int tda8083_init(struct dvb_frontend* fe)
329{ 329{
330 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 330 struct tda8083_state* state = fe->demodulator_priv;
331 int i; 331 int i;
332 332
333 for (i=0; i<44; i++) 333 for (i=0; i<44; i++)
@@ -343,7 +343,7 @@ static int tda8083_init(struct dvb_frontend* fe)
343 343
344static int tda8083_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 344static int tda8083_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
345{ 345{
346 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 346 struct tda8083_state* state = fe->demodulator_priv;
347 347
348 tda8083_send_diseqc_burst (state, burst); 348 tda8083_send_diseqc_burst (state, burst);
349 tda8083_writereg (state, 0x00, 0x3c); 349 tda8083_writereg (state, 0x00, 0x3c);
@@ -354,7 +354,7 @@ static int tda8083_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
354 354
355static int tda8083_diseqc_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 355static int tda8083_diseqc_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
356{ 356{
357 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 357 struct tda8083_state* state = fe->demodulator_priv;
358 358
359 tda8083_set_tone (state, tone); 359 tda8083_set_tone (state, tone);
360 tda8083_writereg (state, 0x00, 0x3c); 360 tda8083_writereg (state, 0x00, 0x3c);
@@ -365,7 +365,7 @@ static int tda8083_diseqc_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t t
365 365
366static int tda8083_diseqc_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 366static int tda8083_diseqc_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
367{ 367{
368 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 368 struct tda8083_state* state = fe->demodulator_priv;
369 369
370 tda8083_set_voltage (state, voltage); 370 tda8083_set_voltage (state, voltage);
371 tda8083_writereg (state, 0x00, 0x3c); 371 tda8083_writereg (state, 0x00, 0x3c);
@@ -376,7 +376,7 @@ static int tda8083_diseqc_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t
376 376
377static void tda8083_release(struct dvb_frontend* fe) 377static void tda8083_release(struct dvb_frontend* fe)
378{ 378{
379 struct tda8083_state* state = (struct tda8083_state*) fe->demodulator_priv; 379 struct tda8083_state* state = fe->demodulator_priv;
380 kfree(state); 380 kfree(state);
381} 381}
382 382
@@ -388,7 +388,7 @@ struct dvb_frontend* tda8083_attach(const struct tda8083_config* config,
388 struct tda8083_state* state = NULL; 388 struct tda8083_state* state = NULL;
389 389
390 /* allocate memory for the internal state */ 390 /* allocate memory for the internal state */
391 state = (struct tda8083_state*) kmalloc(sizeof(struct tda8083_state), GFP_KERNEL); 391 state = kmalloc(sizeof(struct tda8083_state), GFP_KERNEL);
392 if (state == NULL) goto error; 392 if (state == NULL) goto error;
393 393
394 /* setup the state */ 394 /* setup the state */
diff --git a/drivers/media/dvb/frontends/tda80xx.c b/drivers/media/dvb/frontends/tda80xx.c
index c99632114283..032d348dafb7 100644
--- a/drivers/media/dvb/frontends/tda80xx.c
+++ b/drivers/media/dvb/frontends/tda80xx.c
@@ -27,7 +27,7 @@
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/threads.h> 28#include <linux/threads.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <asm/irq.h> 30#include <linux/irq.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
@@ -400,7 +400,7 @@ static void tda80xx_wait_diseqc_fifo(struct tda80xx_state* state)
400 400
401static int tda8044_init(struct dvb_frontend* fe) 401static int tda8044_init(struct dvb_frontend* fe)
402{ 402{
403 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 403 struct tda80xx_state* state = fe->demodulator_priv;
404 int ret; 404 int ret;
405 405
406 /* 406 /*
@@ -432,7 +432,7 @@ static int tda8044_init(struct dvb_frontend* fe)
432 432
433static int tda8083_init(struct dvb_frontend* fe) 433static int tda8083_init(struct dvb_frontend* fe)
434{ 434{
435 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 435 struct tda80xx_state* state = fe->demodulator_priv;
436 436
437 tda80xx_write(state, 0x00, tda8083_inittab, sizeof(tda8083_inittab)); 437 tda80xx_write(state, 0x00, tda8083_inittab, sizeof(tda8083_inittab));
438 438
@@ -447,7 +447,7 @@ static int tda8083_init(struct dvb_frontend* fe)
447 447
448static int tda80xx_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 448static int tda80xx_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
449{ 449{
450 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 450 struct tda80xx_state* state = fe->demodulator_priv;
451 451
452 switch (voltage) { 452 switch (voltage) {
453 case SEC_VOLTAGE_13: 453 case SEC_VOLTAGE_13:
@@ -463,7 +463,7 @@ static int tda80xx_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage
463 463
464static int tda80xx_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 464static int tda80xx_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
465{ 465{
466 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 466 struct tda80xx_state* state = fe->demodulator_priv;
467 467
468 switch (tone) { 468 switch (tone) {
469 case SEC_TONE_OFF: 469 case SEC_TONE_OFF:
@@ -477,7 +477,7 @@ static int tda80xx_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
477 477
478static int tda80xx_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd) 478static int tda80xx_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
479{ 479{
480 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 480 struct tda80xx_state* state = fe->demodulator_priv;
481 481
482 if (cmd->msg_len > 6) 482 if (cmd->msg_len > 6)
483 return -EINVAL; 483 return -EINVAL;
@@ -492,7 +492,7 @@ static int tda80xx_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_ma
492 492
493static int tda80xx_send_diseqc_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t cmd) 493static int tda80xx_send_diseqc_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t cmd)
494{ 494{
495 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 495 struct tda80xx_state* state = fe->demodulator_priv;
496 496
497 switch (cmd) { 497 switch (cmd) {
498 case SEC_MINI_A: 498 case SEC_MINI_A:
@@ -512,7 +512,7 @@ static int tda80xx_send_diseqc_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
512 512
513static int tda80xx_sleep(struct dvb_frontend* fe) 513static int tda80xx_sleep(struct dvb_frontend* fe)
514{ 514{
515 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 515 struct tda80xx_state* state = fe->demodulator_priv;
516 516
517 tda80xx_writereg(state, 0x00, 0x02); /* enter standby */ 517 tda80xx_writereg(state, 0x00, 0x02); /* enter standby */
518 518
@@ -521,7 +521,7 @@ static int tda80xx_sleep(struct dvb_frontend* fe)
521 521
522static int tda80xx_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 522static int tda80xx_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
523{ 523{
524 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 524 struct tda80xx_state* state = fe->demodulator_priv;
525 525
526 tda80xx_writereg(state, 0x1c, 0x80); 526 tda80xx_writereg(state, 0x1c, 0x80);
527 state->config->pll_set(fe, p); 527 state->config->pll_set(fe, p);
@@ -537,7 +537,7 @@ static int tda80xx_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
537 537
538static int tda80xx_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 538static int tda80xx_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
539{ 539{
540 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 540 struct tda80xx_state* state = fe->demodulator_priv;
541 541
542 if (!state->config->irq) 542 if (!state->config->irq)
543 tda80xx_read_status_int(state); 543 tda80xx_read_status_int(state);
@@ -550,7 +550,7 @@ static int tda80xx_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
550 550
551static int tda80xx_read_status(struct dvb_frontend* fe, fe_status_t* status) 551static int tda80xx_read_status(struct dvb_frontend* fe, fe_status_t* status)
552{ 552{
553 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 553 struct tda80xx_state* state = fe->demodulator_priv;
554 554
555 if (!state->config->irq) 555 if (!state->config->irq)
556 tda80xx_read_status_int(state); 556 tda80xx_read_status_int(state);
@@ -561,7 +561,7 @@ static int tda80xx_read_status(struct dvb_frontend* fe, fe_status_t* status)
561 561
562static int tda80xx_read_ber(struct dvb_frontend* fe, u32* ber) 562static int tda80xx_read_ber(struct dvb_frontend* fe, u32* ber)
563{ 563{
564 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 564 struct tda80xx_state* state = fe->demodulator_priv;
565 int ret; 565 int ret;
566 u8 buf[3]; 566 u8 buf[3];
567 567
@@ -575,7 +575,7 @@ static int tda80xx_read_ber(struct dvb_frontend* fe, u32* ber)
575 575
576static int tda80xx_read_signal_strength(struct dvb_frontend* fe, u16* strength) 576static int tda80xx_read_signal_strength(struct dvb_frontend* fe, u16* strength)
577{ 577{
578 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 578 struct tda80xx_state* state = fe->demodulator_priv;
579 579
580 u8 gain = ~tda80xx_readreg(state, 0x01); 580 u8 gain = ~tda80xx_readreg(state, 0x01);
581 *strength = (gain << 8) | gain; 581 *strength = (gain << 8) | gain;
@@ -585,7 +585,7 @@ static int tda80xx_read_signal_strength(struct dvb_frontend* fe, u16* strength)
585 585
586static int tda80xx_read_snr(struct dvb_frontend* fe, u16* snr) 586static int tda80xx_read_snr(struct dvb_frontend* fe, u16* snr)
587{ 587{
588 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 588 struct tda80xx_state* state = fe->demodulator_priv;
589 589
590 u8 quality = tda80xx_readreg(state, 0x08); 590 u8 quality = tda80xx_readreg(state, 0x08);
591 *snr = (quality << 8) | quality; 591 *snr = (quality << 8) | quality;
@@ -595,7 +595,7 @@ static int tda80xx_read_snr(struct dvb_frontend* fe, u16* snr)
595 595
596static int tda80xx_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 596static int tda80xx_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
597{ 597{
598 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 598 struct tda80xx_state* state = fe->demodulator_priv;
599 599
600 *ucblocks = tda80xx_readreg(state, 0x0f); 600 *ucblocks = tda80xx_readreg(state, 0x0f);
601 if (*ucblocks == 0xff) 601 if (*ucblocks == 0xff)
@@ -606,7 +606,7 @@ static int tda80xx_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
606 606
607static int tda80xx_init(struct dvb_frontend* fe) 607static int tda80xx_init(struct dvb_frontend* fe)
608{ 608{
609 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 609 struct tda80xx_state* state = fe->demodulator_priv;
610 610
611 switch(state->id) { 611 switch(state->id) {
612 case ID_TDA8044: 612 case ID_TDA8044:
@@ -620,7 +620,7 @@ static int tda80xx_init(struct dvb_frontend* fe)
620 620
621static void tda80xx_release(struct dvb_frontend* fe) 621static void tda80xx_release(struct dvb_frontend* fe)
622{ 622{
623 struct tda80xx_state* state = (struct tda80xx_state*) fe->demodulator_priv; 623 struct tda80xx_state* state = fe->demodulator_priv;
624 624
625 if (state->config->irq) 625 if (state->config->irq)
626 free_irq(state->config->irq, &state->worklet); 626 free_irq(state->config->irq, &state->worklet);
@@ -637,7 +637,7 @@ struct dvb_frontend* tda80xx_attach(const struct tda80xx_config* config,
637 int ret; 637 int ret;
638 638
639 /* allocate memory for the internal state */ 639 /* allocate memory for the internal state */
640 state = (struct tda80xx_state*) kmalloc(sizeof(struct tda80xx_state), GFP_KERNEL); 640 state = kmalloc(sizeof(struct tda80xx_state), GFP_KERNEL);
641 if (state == NULL) goto error; 641 if (state == NULL) goto error;
642 642
643 /* setup the state */ 643 /* setup the state */
diff --git a/drivers/media/dvb/frontends/ves1820.c b/drivers/media/dvb/frontends/ves1820.c
index 9c0d23e1d9e5..70fb44b391a7 100644
--- a/drivers/media/dvb/frontends/ves1820.c
+++ b/drivers/media/dvb/frontends/ves1820.c
@@ -70,7 +70,6 @@ static int ves1820_writereg(struct ves1820_state *state, u8 reg, u8 data)
70 printk("ves1820: %s(): writereg error (reg == 0x%02x," 70 printk("ves1820: %s(): writereg error (reg == 0x%02x,"
71 "val == 0x%02x, ret == %i)\n", __FUNCTION__, reg, data, ret); 71 "val == 0x%02x, ret == %i)\n", __FUNCTION__, reg, data, ret);
72 72
73 msleep(10);
74 return (ret != 1) ? -EREMOTEIO : 0; 73 return (ret != 1) ? -EREMOTEIO : 0;
75} 74}
76 75
@@ -193,7 +192,7 @@ static int ves1820_set_symbolrate(struct ves1820_state *state, u32 symbolrate)
193 192
194static int ves1820_init(struct dvb_frontend* fe) 193static int ves1820_init(struct dvb_frontend* fe)
195{ 194{
196 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 195 struct ves1820_state* state = fe->demodulator_priv;
197 int i; 196 int i;
198 int val; 197 int val;
199 198
@@ -214,7 +213,7 @@ static int ves1820_init(struct dvb_frontend* fe)
214 213
215static int ves1820_set_parameters(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 214static int ves1820_set_parameters(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
216{ 215{
217 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 216 struct ves1820_state* state = fe->demodulator_priv;
218 static const u8 reg0x00[] = { 0x00, 0x04, 0x08, 0x0c, 0x10 }; 217 static const u8 reg0x00[] = { 0x00, 0x04, 0x08, 0x0c, 0x10 };
219 static const u8 reg0x01[] = { 140, 140, 106, 100, 92 }; 218 static const u8 reg0x01[] = { 140, 140, 106, 100, 92 };
220 static const u8 reg0x05[] = { 135, 100, 70, 54, 38 }; 219 static const u8 reg0x05[] = { 135, 100, 70, 54, 38 };
@@ -241,7 +240,7 @@ static int ves1820_set_parameters(struct dvb_frontend* fe, struct dvb_frontend_p
241 240
242static int ves1820_read_status(struct dvb_frontend* fe, fe_status_t* status) 241static int ves1820_read_status(struct dvb_frontend* fe, fe_status_t* status)
243{ 242{
244 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 243 struct ves1820_state* state = fe->demodulator_priv;
245 int sync; 244 int sync;
246 245
247 *status = 0; 246 *status = 0;
@@ -267,7 +266,7 @@ static int ves1820_read_status(struct dvb_frontend* fe, fe_status_t* status)
267 266
268static int ves1820_read_ber(struct dvb_frontend* fe, u32* ber) 267static int ves1820_read_ber(struct dvb_frontend* fe, u32* ber)
269{ 268{
270 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 269 struct ves1820_state* state = fe->demodulator_priv;
271 270
272 u32 _ber = ves1820_readreg(state, 0x14) | 271 u32 _ber = ves1820_readreg(state, 0x14) |
273 (ves1820_readreg(state, 0x15) << 8) | 272 (ves1820_readreg(state, 0x15) << 8) |
@@ -279,7 +278,7 @@ static int ves1820_read_ber(struct dvb_frontend* fe, u32* ber)
279 278
280static int ves1820_read_signal_strength(struct dvb_frontend* fe, u16* strength) 279static int ves1820_read_signal_strength(struct dvb_frontend* fe, u16* strength)
281{ 280{
282 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 281 struct ves1820_state* state = fe->demodulator_priv;
283 282
284 u8 gain = ves1820_readreg(state, 0x17); 283 u8 gain = ves1820_readreg(state, 0x17);
285 *strength = (gain << 8) | gain; 284 *strength = (gain << 8) | gain;
@@ -289,7 +288,7 @@ static int ves1820_read_signal_strength(struct dvb_frontend* fe, u16* strength)
289 288
290static int ves1820_read_snr(struct dvb_frontend* fe, u16* snr) 289static int ves1820_read_snr(struct dvb_frontend* fe, u16* snr)
291{ 290{
292 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 291 struct ves1820_state* state = fe->demodulator_priv;
293 292
294 u8 quality = ~ves1820_readreg(state, 0x18); 293 u8 quality = ~ves1820_readreg(state, 0x18);
295 *snr = (quality << 8) | quality; 294 *snr = (quality << 8) | quality;
@@ -299,7 +298,7 @@ static int ves1820_read_snr(struct dvb_frontend* fe, u16* snr)
299 298
300static int ves1820_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 299static int ves1820_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
301{ 300{
302 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 301 struct ves1820_state* state = fe->demodulator_priv;
303 302
304 *ucblocks = ves1820_readreg(state, 0x13) & 0x7f; 303 *ucblocks = ves1820_readreg(state, 0x13) & 0x7f;
305 if (*ucblocks == 0x7f) 304 if (*ucblocks == 0x7f)
@@ -314,7 +313,7 @@ static int ves1820_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
314 313
315static int ves1820_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 314static int ves1820_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
316{ 315{
317 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 316 struct ves1820_state* state = fe->demodulator_priv;
318 int sync; 317 int sync;
319 s8 afc = 0; 318 s8 afc = 0;
320 319
@@ -345,7 +344,7 @@ static int ves1820_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
345 344
346static int ves1820_sleep(struct dvb_frontend* fe) 345static int ves1820_sleep(struct dvb_frontend* fe)
347{ 346{
348 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 347 struct ves1820_state* state = fe->demodulator_priv;
349 348
350 ves1820_writereg(state, 0x1b, 0x02); /* pdown ADC */ 349 ves1820_writereg(state, 0x1b, 0x02); /* pdown ADC */
351 ves1820_writereg(state, 0x00, 0x80); /* standby */ 350 ves1820_writereg(state, 0x00, 0x80); /* standby */
@@ -364,7 +363,7 @@ static int ves1820_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronten
364 363
365static void ves1820_release(struct dvb_frontend* fe) 364static void ves1820_release(struct dvb_frontend* fe)
366{ 365{
367 struct ves1820_state* state = (struct ves1820_state*) fe->demodulator_priv; 366 struct ves1820_state* state = fe->demodulator_priv;
368 kfree(state); 367 kfree(state);
369} 368}
370 369
@@ -377,7 +376,7 @@ struct dvb_frontend* ves1820_attach(const struct ves1820_config* config,
377 struct ves1820_state* state = NULL; 376 struct ves1820_state* state = NULL;
378 377
379 /* allocate memory for the internal state */ 378 /* allocate memory for the internal state */
380 state = (struct ves1820_state*) kmalloc(sizeof(struct ves1820_state), GFP_KERNEL); 379 state = kmalloc(sizeof(struct ves1820_state), GFP_KERNEL);
381 if (state == NULL) 380 if (state == NULL)
382 goto error; 381 goto error;
383 382
diff --git a/drivers/media/dvb/frontends/ves1x93.c b/drivers/media/dvb/frontends/ves1x93.c
index edcad283aa86..821df8e839d0 100644
--- a/drivers/media/dvb/frontends/ves1x93.c
+++ b/drivers/media/dvb/frontends/ves1x93.c
@@ -263,7 +263,7 @@ static int ves1x93_set_symbolrate (struct ves1x93_state* state, u32 srate)
263 263
264static int ves1x93_init (struct dvb_frontend* fe) 264static int ves1x93_init (struct dvb_frontend* fe)
265{ 265{
266 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 266 struct ves1x93_state* state = fe->demodulator_priv;
267 int i; 267 int i;
268 int val; 268 int val;
269 269
@@ -289,7 +289,7 @@ static int ves1x93_init (struct dvb_frontend* fe)
289 289
290static int ves1x93_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 290static int ves1x93_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
291{ 291{
292 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 292 struct ves1x93_state* state = fe->demodulator_priv;
293 293
294 switch (voltage) { 294 switch (voltage) {
295 case SEC_VOLTAGE_13: 295 case SEC_VOLTAGE_13:
@@ -305,7 +305,7 @@ static int ves1x93_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
305 305
306static int ves1x93_read_status(struct dvb_frontend* fe, fe_status_t* status) 306static int ves1x93_read_status(struct dvb_frontend* fe, fe_status_t* status)
307{ 307{
308 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 308 struct ves1x93_state* state = fe->demodulator_priv;
309 309
310 u8 sync = ves1x93_readreg (state, 0x0e); 310 u8 sync = ves1x93_readreg (state, 0x0e);
311 311
@@ -346,7 +346,7 @@ static int ves1x93_read_status(struct dvb_frontend* fe, fe_status_t* status)
346 346
347static int ves1x93_read_ber(struct dvb_frontend* fe, u32* ber) 347static int ves1x93_read_ber(struct dvb_frontend* fe, u32* ber)
348{ 348{
349 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 349 struct ves1x93_state* state = fe->demodulator_priv;
350 350
351 *ber = ves1x93_readreg (state, 0x15); 351 *ber = ves1x93_readreg (state, 0x15);
352 *ber |= (ves1x93_readreg (state, 0x16) << 8); 352 *ber |= (ves1x93_readreg (state, 0x16) << 8);
@@ -358,7 +358,7 @@ static int ves1x93_read_ber(struct dvb_frontend* fe, u32* ber)
358 358
359static int ves1x93_read_signal_strength(struct dvb_frontend* fe, u16* strength) 359static int ves1x93_read_signal_strength(struct dvb_frontend* fe, u16* strength)
360{ 360{
361 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 361 struct ves1x93_state* state = fe->demodulator_priv;
362 362
363 u8 signal = ~ves1x93_readreg (state, 0x0b); 363 u8 signal = ~ves1x93_readreg (state, 0x0b);
364 *strength = (signal << 8) | signal; 364 *strength = (signal << 8) | signal;
@@ -368,7 +368,7 @@ static int ves1x93_read_signal_strength(struct dvb_frontend* fe, u16* strength)
368 368
369static int ves1x93_read_snr(struct dvb_frontend* fe, u16* snr) 369static int ves1x93_read_snr(struct dvb_frontend* fe, u16* snr)
370{ 370{
371 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 371 struct ves1x93_state* state = fe->demodulator_priv;
372 372
373 u8 _snr = ~ves1x93_readreg (state, 0x1c); 373 u8 _snr = ~ves1x93_readreg (state, 0x1c);
374 *snr = (_snr << 8) | _snr; 374 *snr = (_snr << 8) | _snr;
@@ -378,7 +378,7 @@ static int ves1x93_read_snr(struct dvb_frontend* fe, u16* snr)
378 378
379static int ves1x93_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) 379static int ves1x93_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
380{ 380{
381 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 381 struct ves1x93_state* state = fe->demodulator_priv;
382 382
383 *ucblocks = ves1x93_readreg (state, 0x18) & 0x7f; 383 *ucblocks = ves1x93_readreg (state, 0x18) & 0x7f;
384 384
@@ -393,7 +393,7 @@ static int ves1x93_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
393 393
394static int ves1x93_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 394static int ves1x93_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
395{ 395{
396 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 396 struct ves1x93_state* state = fe->demodulator_priv;
397 397
398 ves1x93_writereg(state, 0x00, 0x11); 398 ves1x93_writereg(state, 0x00, 0x11);
399 state->config->pll_set(fe, p); 399 state->config->pll_set(fe, p);
@@ -408,7 +408,7 @@ static int ves1x93_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
408 408
409static int ves1x93_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 409static int ves1x93_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
410{ 410{
411 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 411 struct ves1x93_state* state = fe->demodulator_priv;
412 int afc; 412 int afc;
413 413
414 afc = ((int)((char)(ves1x93_readreg (state, 0x0a) << 1)))/2; 414 afc = ((int)((char)(ves1x93_readreg (state, 0x0a) << 1)))/2;
@@ -431,14 +431,14 @@ static int ves1x93_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
431 431
432static int ves1x93_sleep(struct dvb_frontend* fe) 432static int ves1x93_sleep(struct dvb_frontend* fe)
433{ 433{
434 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 434 struct ves1x93_state* state = fe->demodulator_priv;
435 435
436 return ves1x93_writereg (state, 0x00, 0x08); 436 return ves1x93_writereg (state, 0x00, 0x08);
437} 437}
438 438
439static void ves1x93_release(struct dvb_frontend* fe) 439static void ves1x93_release(struct dvb_frontend* fe)
440{ 440{
441 struct ves1x93_state* state = (struct ves1x93_state*) fe->demodulator_priv; 441 struct ves1x93_state* state = fe->demodulator_priv;
442 kfree(state); 442 kfree(state);
443} 443}
444 444
@@ -451,7 +451,7 @@ struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config,
451 u8 identity; 451 u8 identity;
452 452
453 /* allocate memory for the internal state */ 453 /* allocate memory for the internal state */
454 state = (struct ves1x93_state*) kmalloc(sizeof(struct ves1x93_state), GFP_KERNEL); 454 state = kmalloc(sizeof(struct ves1x93_state), GFP_KERNEL);
455 if (state == NULL) goto error; 455 if (state == NULL) goto error;
456 456
457 /* setup the state */ 457 /* setup the state */
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 922c205a2652..8e33a850e13e 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -130,7 +130,7 @@ static void init_av7110_av(struct av7110 *av7110)
130 av7110->current_input = 0; 130 av7110->current_input = 0;
131 if (i2c_writereg(av7110, 0x20, 0x00, 0x00) == 1) { 131 if (i2c_writereg(av7110, 0x20, 0x00, 0x00) == 1) {
132 printk ("dvb-ttpci: Crystal audio DAC @ card %d detected\n", 132 printk ("dvb-ttpci: Crystal audio DAC @ card %d detected\n",
133 av7110->dvb_adapter->num); 133 av7110->dvb_adapter.num);
134 av7110->adac_type = DVB_ADAC_CRYSTAL; 134 av7110->adac_type = DVB_ADAC_CRYSTAL;
135 i2c_writereg(av7110, 0x20, 0x01, 0xd2); 135 i2c_writereg(av7110, 0x20, 0x01, 0xd2);
136 i2c_writereg(av7110, 0x20, 0x02, 0x49); 136 i2c_writereg(av7110, 0x20, 0x02, 0x49);
@@ -145,13 +145,13 @@ static void init_av7110_av(struct av7110 *av7110)
145 } 145 }
146 else if (dev->pci->subsystem_vendor == 0x110a) { 146 else if (dev->pci->subsystem_vendor == 0x110a) {
147 printk("dvb-ttpci: DVB-C w/o analog module @ card %d detected\n", 147 printk("dvb-ttpci: DVB-C w/o analog module @ card %d detected\n",
148 av7110->dvb_adapter->num); 148 av7110->dvb_adapter.num);
149 av7110->adac_type = DVB_ADAC_NONE; 149 av7110->adac_type = DVB_ADAC_NONE;
150 } 150 }
151 else { 151 else {
152 av7110->adac_type = adac; 152 av7110->adac_type = adac;
153 printk("dvb-ttpci: adac type set to %d @ card %d\n", 153 printk("dvb-ttpci: adac type set to %d @ card %d\n",
154 av7110->dvb_adapter->num, av7110->adac_type); 154 av7110->dvb_adapter.num, av7110->adac_type);
155 } 155 }
156 156
157 if (av7110->adac_type == DVB_ADAC_NONE || av7110->adac_type == DVB_ADAC_MSP) { 157 if (av7110->adac_type == DVB_ADAC_NONE || av7110->adac_type == DVB_ADAC_MSP) {
@@ -231,7 +231,7 @@ static int arm_thread(void *data)
231 231
232 if (newloops == av7110->arm_loops) { 232 if (newloops == av7110->arm_loops) {
233 printk(KERN_ERR "dvb-ttpci: ARM crashed @ card %d\n", 233 printk(KERN_ERR "dvb-ttpci: ARM crashed @ card %d\n",
234 av7110->dvb_adapter->num); 234 av7110->dvb_adapter.num);
235 235
236 arm_error(av7110); 236 arm_error(av7110);
237 av7710_set_video_mode(av7110, vidmode); 237 av7710_set_video_mode(av7110, vidmode);
@@ -1282,7 +1282,7 @@ static int av7110_register(struct av7110 *av7110)
1282 av7110->dmxdev.demux = &dvbdemux->dmx; 1282 av7110->dmxdev.demux = &dvbdemux->dmx;
1283 av7110->dmxdev.capabilities = 0; 1283 av7110->dmxdev.capabilities = 0;
1284 1284
1285 dvb_dmxdev_init(&av7110->dmxdev, av7110->dvb_adapter); 1285 dvb_dmxdev_init(&av7110->dmxdev, &av7110->dvb_adapter);
1286 1286
1287 av7110->hw_frontend.source = DMX_FRONTEND_0; 1287 av7110->hw_frontend.source = DMX_FRONTEND_0;
1288 1288
@@ -1307,11 +1307,11 @@ static int av7110_register(struct av7110 *av7110)
1307 av7110_ca_register(av7110); 1307 av7110_ca_register(av7110);
1308 1308
1309#ifdef CONFIG_DVB_AV7110_OSD 1309#ifdef CONFIG_DVB_AV7110_OSD
1310 dvb_register_device(av7110->dvb_adapter, &av7110->osd_dev, 1310 dvb_register_device(&av7110->dvb_adapter, &av7110->osd_dev,
1311 &dvbdev_osd, av7110, DVB_DEVICE_OSD); 1311 &dvbdev_osd, av7110, DVB_DEVICE_OSD);
1312#endif 1312#endif
1313 1313
1314 dvb_net_init(av7110->dvb_adapter, &av7110->dvb_net, &dvbdemux->dmx); 1314 dvb_net_init(&av7110->dvb_adapter, &av7110->dvb_net, &dvbdemux->dmx);
1315 1315
1316 if (budgetpatch) { 1316 if (budgetpatch) {
1317 /* initialize software demux1 without its own frontend 1317 /* initialize software demux1 without its own frontend
@@ -1334,9 +1334,9 @@ static int av7110_register(struct av7110 *av7110)
1334 av7110->dmxdev1.demux = &dvbdemux1->dmx; 1334 av7110->dmxdev1.demux = &dvbdemux1->dmx;
1335 av7110->dmxdev1.capabilities = 0; 1335 av7110->dmxdev1.capabilities = 0;
1336 1336
1337 dvb_dmxdev_init(&av7110->dmxdev1, av7110->dvb_adapter); 1337 dvb_dmxdev_init(&av7110->dmxdev1, &av7110->dvb_adapter);
1338 1338
1339 dvb_net_init(av7110->dvb_adapter, &av7110->dvb_net1, &dvbdemux1->dmx); 1339 dvb_net_init(&av7110->dvb_adapter, &av7110->dvb_net1, &dvbdemux1->dmx);
1340 printk("dvb-ttpci: additional demux1 for budget-patch registered\n"); 1340 printk("dvb-ttpci: additional demux1 for budget-patch registered\n");
1341 } 1341 }
1342 return 0; 1342 return 0;
@@ -1673,6 +1673,106 @@ static struct stv0299_config alps_bsru6_config = {
1673}; 1673};
1674 1674
1675 1675
1676static u8 alps_bsbe1_inittab[] = {
1677 0x01, 0x15,
1678 0x02, 0x30,
1679 0x03, 0x00,
1680 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1681 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1682 0x06, 0x40, /* DAC not used, set to high impendance mode */
1683 0x07, 0x00, /* DAC LSB */
1684 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1685 0x09, 0x00, /* FIFO */
1686 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1687 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1688 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1689 0x10, 0x3f, // AGC2 0x3d
1690 0x11, 0x84,
1691 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on
1692 0x15, 0xc9, // lock detector threshold
1693 0x16, 0x00,
1694 0x17, 0x00,
1695 0x18, 0x00,
1696 0x19, 0x00,
1697 0x1a, 0x00,
1698 0x1f, 0x50,
1699 0x20, 0x00,
1700 0x21, 0x00,
1701 0x22, 0x00,
1702 0x23, 0x00,
1703 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1704 0x29, 0x1e, // 1/2 threshold
1705 0x2a, 0x14, // 2/3 threshold
1706 0x2b, 0x0f, // 3/4 threshold
1707 0x2c, 0x09, // 5/6 threshold
1708 0x2d, 0x05, // 7/8 threshold
1709 0x2e, 0x01,
1710 0x31, 0x1f, // test all FECs
1711 0x32, 0x19, // viterbi and synchro search
1712 0x33, 0xfc, // rs control
1713 0x34, 0x93, // error control
1714 0x0f, 0x92,
1715 0xff, 0xff
1716};
1717
1718static int alps_bsbe1_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1719{
1720 struct av7110* av7110 = (struct av7110*) fe->dvb->priv;
1721 int ret;
1722 u8 data[4];
1723 u32 div;
1724 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
1725
1726 if ((params->frequency < 950000) || (params->frequency > 2150000))
1727 return -EINVAL;
1728
1729 div = (params->frequency + (125 - 1)) / 125; // round correctly
1730 data[0] = (div >> 8) & 0x7f;
1731 data[1] = div & 0xff;
1732 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
1733 data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4;
1734
1735 ret = i2c_transfer(&av7110->i2c_adap, &msg, 1);
1736 return (ret != 1) ? -EIO : 0;
1737}
1738
1739static struct stv0299_config alps_bsbe1_config = {
1740 .demod_address = 0x68,
1741 .inittab = alps_bsbe1_inittab,
1742 .mclk = 88000000UL,
1743 .invert = 1,
1744 .enhanced_tuning = 0,
1745 .skip_reinit = 0,
1746 .min_delay_ms = 100,
1747 .set_symbol_rate = alps_bsru6_set_symbol_rate,
1748 .pll_set = alps_bsbe1_pll_set,
1749};
1750
1751static int lnbp21_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
1752{
1753 struct av7110* av7110 = (struct av7110*) fe->dvb->priv;
1754 int ret;
1755 u8 data[1];
1756 struct i2c_msg msg = { .addr = 0x08, .flags = 0, .buf = data, .len = sizeof(data) };
1757
1758 switch(voltage) {
1759 case SEC_VOLTAGE_OFF:
1760 data[0] = 0x00;
1761 break;
1762 case SEC_VOLTAGE_13:
1763 data[0] = 0x44;
1764 break;
1765 case SEC_VOLTAGE_18:
1766 data[0] = 0x4c;
1767 break;
1768 default:
1769 return -EINVAL;
1770 };
1771
1772 ret = i2c_transfer(&av7110->i2c_adap, &msg, 1);
1773 return (ret != 1) ? -EIO : 0;
1774}
1775
1676 1776
1677static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 1777static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1678{ 1778{
@@ -2116,6 +2216,14 @@ static int frontend_init(struct av7110 *av7110)
2116 av7110->dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240; 2216 av7110->dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240;
2117 break; 2217 break;
2118 } 2218 }
2219 break;
2220
2221 case 0x000E: /* Hauppauge/TT Nexus-S rev 2.3 */
2222 /* ALPS BSBE1 */
2223 av7110->fe = stv0299_attach(&alps_bsbe1_config, &av7110->i2c_adap);
2224 if (av7110->fe)
2225 av7110->fe->ops->set_voltage = lnbp21_set_voltage;
2226 break;
2119 } 2227 }
2120 } 2228 }
2121 2229
@@ -2138,7 +2246,7 @@ static int frontend_init(struct av7110 *av7110)
2138 FE_FUNC_OVERRIDE(av7110->fe->ops->dishnetwork_send_legacy_command, av7110->fe_dishnetwork_send_legacy_command, av7110_fe_dishnetwork_send_legacy_command); 2246 FE_FUNC_OVERRIDE(av7110->fe->ops->dishnetwork_send_legacy_command, av7110->fe_dishnetwork_send_legacy_command, av7110_fe_dishnetwork_send_legacy_command);
2139 FE_FUNC_OVERRIDE(av7110->fe->ops->set_frontend, av7110->fe_set_frontend, av7110_fe_set_frontend); 2247 FE_FUNC_OVERRIDE(av7110->fe->ops->set_frontend, av7110->fe_set_frontend, av7110_fe_set_frontend);
2140 2248
2141 ret = dvb_register_frontend(av7110->dvb_adapter, av7110->fe); 2249 ret = dvb_register_frontend(&av7110->dvb_adapter, av7110->fe);
2142 if (ret < 0) { 2250 if (ret < 0) {
2143 printk("av7110: Frontend registration failed!\n"); 2251 printk("av7110: Frontend registration failed!\n");
2144 if (av7110->fe->ops->release) 2252 if (av7110->fe->ops->release)
@@ -2352,7 +2460,7 @@ static int av7110_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_d
2352 goto err_dvb_unregister_adapter_2; 2460 goto err_dvb_unregister_adapter_2;
2353 2461
2354 ttpci_eeprom_parse_mac(&av7110->i2c_adap, 2462 ttpci_eeprom_parse_mac(&av7110->i2c_adap,
2355 av7110->dvb_adapter->proposed_mac); 2463 av7110->dvb_adapter.proposed_mac);
2356 ret = -ENOMEM; 2464 ret = -ENOMEM;
2357 2465
2358 if (budgetpatch) { 2466 if (budgetpatch) {
@@ -2523,7 +2631,7 @@ static int av7110_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_d
2523 if (ret < 0) 2631 if (ret < 0)
2524 goto err_av7110_unregister_11; 2632 goto err_av7110_unregister_11;
2525 2633
2526 av7110->dvb_adapter->priv = av7110; 2634 av7110->dvb_adapter.priv = av7110;
2527 ret = frontend_init(av7110); 2635 ret = frontend_init(av7110);
2528 if (ret < 0) 2636 if (ret < 0)
2529 goto err_av7110_exit_v4l_12; 2637 goto err_av7110_exit_v4l_12;
@@ -2558,7 +2666,7 @@ err_saa71466_vfree_4:
2558err_i2c_del_3: 2666err_i2c_del_3:
2559 i2c_del_adapter(&av7110->i2c_adap); 2667 i2c_del_adapter(&av7110->i2c_adap);
2560err_dvb_unregister_adapter_2: 2668err_dvb_unregister_adapter_2:
2561 dvb_unregister_adapter(av7110->dvb_adapter); 2669 dvb_unregister_adapter(&av7110->dvb_adapter);
2562err_put_firmware_1: 2670err_put_firmware_1:
2563 put_firmware(av7110); 2671 put_firmware(av7110);
2564err_kfree_0: 2672err_kfree_0:
@@ -2604,7 +2712,7 @@ static int av7110_detach(struct saa7146_dev* saa)
2604 2712
2605 i2c_del_adapter(&av7110->i2c_adap); 2713 i2c_del_adapter(&av7110->i2c_adap);
2606 2714
2607 dvb_unregister_adapter (av7110->dvb_adapter); 2715 dvb_unregister_adapter (&av7110->dvb_adapter);
2608 2716
2609 av7110_num--; 2717 av7110_num--;
2610 2718
@@ -2672,21 +2780,23 @@ MAKE_AV7110_INFO(ttt_1_X, "Technotrend/Hauppauge WinTV DVB-T rev1.X");
2672MAKE_AV7110_INFO(ttc_1_X, "Technotrend/Hauppauge WinTV Nexus-CA rev1.X"); 2780MAKE_AV7110_INFO(ttc_1_X, "Technotrend/Hauppauge WinTV Nexus-CA rev1.X");
2673MAKE_AV7110_INFO(ttc_2_X, "Technotrend/Hauppauge WinTV DVB-C rev2.X"); 2781MAKE_AV7110_INFO(ttc_2_X, "Technotrend/Hauppauge WinTV DVB-C rev2.X");
2674MAKE_AV7110_INFO(tts_2_X, "Technotrend/Hauppauge WinTV Nexus-S rev2.X"); 2782MAKE_AV7110_INFO(tts_2_X, "Technotrend/Hauppauge WinTV Nexus-S rev2.X");
2783MAKE_AV7110_INFO(tts_2_3, "Technotrend/Hauppauge WinTV Nexus-S rev2.3");
2675MAKE_AV7110_INFO(tts_1_3se, "Technotrend/Hauppauge WinTV DVB-S rev1.3 SE"); 2784MAKE_AV7110_INFO(tts_1_3se, "Technotrend/Hauppauge WinTV DVB-S rev1.3 SE");
2676MAKE_AV7110_INFO(ttt, "Technotrend/Hauppauge DVB-T"); 2785MAKE_AV7110_INFO(ttt, "Technotrend/Hauppauge DVB-T");
2677MAKE_AV7110_INFO(fsc, "Fujitsu Siemens DVB-C"); 2786MAKE_AV7110_INFO(fsc, "Fujitsu Siemens DVB-C");
2678MAKE_AV7110_INFO(fss, "Fujitsu Siemens DVB-S rev1.6"); 2787MAKE_AV7110_INFO(fss, "Fujitsu Siemens DVB-S rev1.6");
2679 2788
2680static struct pci_device_id pci_tbl[] = { 2789static struct pci_device_id pci_tbl[] = {
2790 MAKE_EXTENSION_PCI(fsc, 0x110a, 0x0000),
2681 MAKE_EXTENSION_PCI(tts_1_X, 0x13c2, 0x0000), 2791 MAKE_EXTENSION_PCI(tts_1_X, 0x13c2, 0x0000),
2682 MAKE_EXTENSION_PCI(ttt_1_X, 0x13c2, 0x0001), 2792 MAKE_EXTENSION_PCI(ttt_1_X, 0x13c2, 0x0001),
2683 MAKE_EXTENSION_PCI(ttc_2_X, 0x13c2, 0x0002), 2793 MAKE_EXTENSION_PCI(ttc_2_X, 0x13c2, 0x0002),
2684 MAKE_EXTENSION_PCI(tts_2_X, 0x13c2, 0x0003), 2794 MAKE_EXTENSION_PCI(tts_2_X, 0x13c2, 0x0003),
2685 MAKE_EXTENSION_PCI(tts_1_3se, 0x13c2, 0x1002),
2686 MAKE_EXTENSION_PCI(fsc, 0x110a, 0x0000),
2687 MAKE_EXTENSION_PCI(ttc_1_X, 0x13c2, 0x000a),
2688 MAKE_EXTENSION_PCI(fss, 0x13c2, 0x0006), 2795 MAKE_EXTENSION_PCI(fss, 0x13c2, 0x0006),
2689 MAKE_EXTENSION_PCI(ttt, 0x13c2, 0x0008), 2796 MAKE_EXTENSION_PCI(ttt, 0x13c2, 0x0008),
2797 MAKE_EXTENSION_PCI(ttc_1_X, 0x13c2, 0x000a),
2798 MAKE_EXTENSION_PCI(tts_2_3, 0x13c2, 0x000e),
2799 MAKE_EXTENSION_PCI(tts_1_3se, 0x13c2, 0x1002),
2690 2800
2691/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0004), UNDEFINED CARD */ // Galaxis DVB PC-Sat-Carte 2801/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0004), UNDEFINED CARD */ // Galaxis DVB PC-Sat-Carte
2692/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0005), UNDEFINED CARD */ // Technisat SkyStar1 2802/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0005), UNDEFINED CARD */ // Technisat SkyStar1
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index 5070e0523da7..4f69b4d01479 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -220,7 +220,7 @@ struct av7110 {
220 220
221 struct audio_mixer mixer; 221 struct audio_mixer mixer;
222 222
223 struct dvb_adapter *dvb_adapter; 223 struct dvb_adapter dvb_adapter;
224 struct dvb_device *video_dev; 224 struct dvb_device *video_dev;
225 struct dvb_device *audio_dev; 225 struct dvb_device *audio_dev;
226 struct dvb_device *ca_dev; 226 struct dvb_device *ca_dev;
@@ -274,7 +274,6 @@ extern void av7110_ir_exit (void);
274extern int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val); 274extern int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val);
275extern u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg); 275extern u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg);
276extern int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val); 276extern int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val);
277extern int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val);
278 277
279 278
280extern int av7110_init_analog_module(struct av7110 *av7110); 279extern int av7110_init_analog_module(struct av7110 *av7110);
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index d77e8a00688f..ccf946125d02 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -1075,7 +1075,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
1075 } 1075 }
1076 if (ret < 0) 1076 if (ret < 0)
1077 break; 1077 break;
1078 av7110->videostate.video_format = format; 1078 av7110->videostate.display_format = format;
1079 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType, 1079 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType,
1080 1, (u16) val); 1080 1, (u16) val);
1081 break; 1081 break;
@@ -1230,14 +1230,20 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1230 switch(av7110->audiostate.channel_select) { 1230 switch(av7110->audiostate.channel_select) {
1231 case AUDIO_STEREO: 1231 case AUDIO_STEREO:
1232 audcom(av7110, AUDIO_CMD_STEREO); 1232 audcom(av7110, AUDIO_CMD_STEREO);
1233 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1234 i2c_writereg(av7110, 0x20, 0x02, 0x49);
1233 break; 1235 break;
1234 1236
1235 case AUDIO_MONO_LEFT: 1237 case AUDIO_MONO_LEFT:
1236 audcom(av7110, AUDIO_CMD_MONO_L); 1238 audcom(av7110, AUDIO_CMD_MONO_L);
1239 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1240 i2c_writereg(av7110, 0x20, 0x02, 0x4a);
1237 break; 1241 break;
1238 1242
1239 case AUDIO_MONO_RIGHT: 1243 case AUDIO_MONO_RIGHT:
1240 audcom(av7110, AUDIO_CMD_MONO_R); 1244 audcom(av7110, AUDIO_CMD_MONO_R);
1245 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1246 i2c_writereg(av7110, 0x20, 0x02, 0x45);
1241 break; 1247 break;
1242 1248
1243 default: 1249 default:
@@ -1409,10 +1415,10 @@ int av7110_av_register(struct av7110 *av7110)
1409 av7110->video_events.overflow = 0; 1415 av7110->video_events.overflow = 0;
1410 memset(&av7110->video_size, 0, sizeof (video_size_t)); 1416 memset(&av7110->video_size, 0, sizeof (video_size_t));
1411 1417
1412 dvb_register_device(av7110->dvb_adapter, &av7110->video_dev, 1418 dvb_register_device(&av7110->dvb_adapter, &av7110->video_dev,
1413 &dvbdev_video, av7110, DVB_DEVICE_VIDEO); 1419 &dvbdev_video, av7110, DVB_DEVICE_VIDEO);
1414 1420
1415 dvb_register_device(av7110->dvb_adapter, &av7110->audio_dev, 1421 dvb_register_device(&av7110->dvb_adapter, &av7110->audio_dev,
1416 &dvbdev_audio, av7110, DVB_DEVICE_AUDIO); 1422 &dvbdev_audio, av7110, DVB_DEVICE_AUDIO);
1417 1423
1418 return 0; 1424 return 0;
diff --git a/drivers/media/dvb/ttpci/av7110_ca.c b/drivers/media/dvb/ttpci/av7110_ca.c
index 21f7aacf7726..c3801e328fe9 100644
--- a/drivers/media/dvb/ttpci/av7110_ca.c
+++ b/drivers/media/dvb/ttpci/av7110_ca.c
@@ -123,7 +123,7 @@ static void ci_ll_release(struct dvb_ringbuffer *cirbuf, struct dvb_ringbuffer *
123} 123}
124 124
125static int ci_ll_reset(struct dvb_ringbuffer *cibuf, struct file *file, 125static int ci_ll_reset(struct dvb_ringbuffer *cibuf, struct file *file,
126 int slots, ca_slot_info_t *slot) 126 int slots, ca_slot_info_t *slot)
127{ 127{
128 int i; 128 int i;
129 int len = 0; 129 int len = 0;
@@ -370,7 +370,7 @@ static struct dvb_device dvbdev_ca = {
370 370
371int av7110_ca_register(struct av7110 *av7110) 371int av7110_ca_register(struct av7110 *av7110)
372{ 372{
373 return dvb_register_device(av7110->dvb_adapter, &av7110->ca_dev, 373 return dvb_register_device(&av7110->dvb_adapter, &av7110->ca_dev,
374 &dvbdev_ca, av7110, DVB_DEVICE_CA); 374 &dvbdev_ca, av7110, DVB_DEVICE_CA);
375} 375}
376 376
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index bd6e5ea4aefe..7fa4a0ebe133 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -104,7 +104,7 @@ u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, int count)
104 104
105 105
106/* av7110 ARM core boot stuff */ 106/* av7110 ARM core boot stuff */
107 107#if 0
108void av7110_reset_arm(struct av7110 *av7110) 108void av7110_reset_arm(struct av7110 *av7110)
109{ 109{
110 saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTLO); 110 saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTLO);
@@ -124,7 +124,7 @@ void av7110_reset_arm(struct av7110 *av7110)
124 av7110->arm_ready = 1; 124 av7110->arm_ready = 1;
125 dprintk(1, "reset ARM\n"); 125 dprintk(1, "reset ARM\n");
126} 126}
127 127#endif /* 0 */
128 128
129static int waitdebi(struct av7110 *av7110, int adr, int state) 129static int waitdebi(struct av7110 *av7110, int adr, int state)
130{ 130{
@@ -335,7 +335,7 @@ int av7110_wait_msgstate(struct av7110 *av7110, u16 flags)
335 return 0; 335 return 0;
336} 336}
337 337
338int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length) 338static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
339{ 339{
340 int i; 340 int i;
341 unsigned long start; 341 unsigned long start;
@@ -455,7 +455,7 @@ int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
455 return 0; 455 return 0;
456} 456}
457 457
458int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length) 458static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
459{ 459{
460 int ret; 460 int ret;
461 461
@@ -500,6 +500,7 @@ int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
500 return ret; 500 return ret;
501} 501}
502 502
503#if 0
503int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len) 504int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len)
504{ 505{
505 int i, ret; 506 int i, ret;
@@ -521,6 +522,7 @@ int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len)
521 printk(KERN_ERR "dvb-ttpci: av7110_send_ci_cmd error %d\n", ret); 522 printk(KERN_ERR "dvb-ttpci: av7110_send_ci_cmd error %d\n", ret);
522 return ret; 523 return ret;
523} 524}
525#endif /* 0 */
524 526
525int av7110_fw_request(struct av7110 *av7110, u16 *request_buf, 527int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
526 int request_buf_len, u16 *reply_buf, int reply_buf_len) 528 int request_buf_len, u16 *reply_buf, int reply_buf_len)
@@ -593,7 +595,7 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
593 return 0; 595 return 0;
594} 596}
595 597
596int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* buf, s16 length) 598static int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* buf, s16 length)
597{ 599{
598 int ret; 600 int ret;
599 ret = av7110_fw_request(av7110, &tag, 0, buf, length); 601 ret = av7110_fw_request(av7110, &tag, 0, buf, length);
@@ -617,7 +619,7 @@ int av7110_firmversion(struct av7110 *av7110)
617 619
618 if (av7110_fw_query(av7110, tag, buf, 16)) { 620 if (av7110_fw_query(av7110, tag, buf, 16)) {
619 printk("dvb-ttpci: failed to boot firmware @ card %d\n", 621 printk("dvb-ttpci: failed to boot firmware @ card %d\n",
620 av7110->dvb_adapter->num); 622 av7110->dvb_adapter.num);
621 return -EIO; 623 return -EIO;
622 } 624 }
623 625
@@ -628,16 +630,16 @@ int av7110_firmversion(struct av7110 *av7110)
628 av7110->avtype = (buf[8] << 16) + buf[9]; 630 av7110->avtype = (buf[8] << 16) + buf[9];
629 631
630 printk("dvb-ttpci: info @ card %d: firm %08x, rtsl %08x, vid %08x, app %08x\n", 632 printk("dvb-ttpci: info @ card %d: firm %08x, rtsl %08x, vid %08x, app %08x\n",
631 av7110->dvb_adapter->num, av7110->arm_fw, 633 av7110->dvb_adapter.num, av7110->arm_fw,
632 av7110->arm_rtsl, av7110->arm_vid, av7110->arm_app); 634 av7110->arm_rtsl, av7110->arm_vid, av7110->arm_app);
633 635
634 /* print firmware capabilities */ 636 /* print firmware capabilities */
635 if (FW_CI_LL_SUPPORT(av7110->arm_app)) 637 if (FW_CI_LL_SUPPORT(av7110->arm_app))
636 printk("dvb-ttpci: firmware @ card %d supports CI link layer interface\n", 638 printk("dvb-ttpci: firmware @ card %d supports CI link layer interface\n",
637 av7110->dvb_adapter->num); 639 av7110->dvb_adapter.num);
638 else 640 else
639 printk("dvb-ttpci: no firmware support for CI link layer interface @ card %d\n", 641 printk("dvb-ttpci: no firmware support for CI link layer interface @ card %d\n",
640 av7110->dvb_adapter->num); 642 av7110->dvb_adapter.num);
641 643
642 return 0; 644 return 0;
643} 645}
diff --git a/drivers/media/dvb/ttpci/av7110_hw.h b/drivers/media/dvb/ttpci/av7110_hw.h
index bf901c624682..52061e17c6dd 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.h
+++ b/drivers/media/dvb/ttpci/av7110_hw.h
@@ -364,7 +364,6 @@ enum av7110_command_type {
364 364
365 365
366 366
367extern void av7110_reset_arm(struct av7110 *av7110);
368extern int av7110_bootarm(struct av7110 *av7110); 367extern int av7110_bootarm(struct av7110 *av7110);
369extern int av7110_firmversion(struct av7110 *av7110); 368extern int av7110_firmversion(struct av7110 *av7110);
370#define FW_CI_LL_SUPPORT(arm_app) ((arm_app) & 0x80000000) 369#define FW_CI_LL_SUPPORT(arm_app) ((arm_app) & 0x80000000)
@@ -373,12 +372,8 @@ extern int av7110_firmversion(struct av7110 *av7110);
373 372
374extern int av7110_wait_msgstate(struct av7110 *av7110, u16 flags); 373extern int av7110_wait_msgstate(struct av7110 *av7110, u16 flags);
375extern int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...); 374extern int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...);
376extern int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length);
377extern int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length);
378extern int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len);
379extern int av7110_fw_request(struct av7110 *av7110, u16 *request_buf, 375extern int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
380 int request_buf_len, u16 *reply_buf, int reply_buf_len); 376 int request_buf_len, u16 *reply_buf, int reply_buf_len);
381extern int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* Buff, s16 length);
382 377
383 378
384/* DEBI (saa7146 data extension bus interface) access */ 379/* DEBI (saa7146 data extension bus interface) access */
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index 6d2256f1e354..665cdb8a3f71 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -10,7 +10,7 @@
10 10
11#define UP_TIMEOUT (HZ/4) 11#define UP_TIMEOUT (HZ/4)
12 12
13/* enable ir debugging by or'ing av7110_debug with 16 */ 13/* enable ir debugging by or'ing debug with 16 */
14 14
15static int ir_initialized; 15static int ir_initialized;
16static struct input_dev input_dev; 16static struct input_dev input_dev;
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index eb84fb08d95c..e65fc36e2ce8 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -46,13 +46,13 @@ int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val)
46 46
47 if (i2c_transfer(&av7110->i2c_adap, &msgs, 1) != 1) { 47 if (i2c_transfer(&av7110->i2c_adap, &msgs, 1) != 1) {
48 dprintk(1, "dvb-ttpci: failed @ card %d, %u = %u\n", 48 dprintk(1, "dvb-ttpci: failed @ card %d, %u = %u\n",
49 av7110->dvb_adapter->num, reg, val); 49 av7110->dvb_adapter.num, reg, val);
50 return -EIO; 50 return -EIO;
51 } 51 }
52 return 0; 52 return 0;
53} 53}
54 54
55int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val) 55static int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val)
56{ 56{
57 u8 msg1[3] = { dev, reg >> 8, reg & 0xff }; 57 u8 msg1[3] = { dev, reg >> 8, reg & 0xff };
58 u8 msg2[2]; 58 u8 msg2[2];
@@ -63,7 +63,7 @@ int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val)
63 63
64 if (i2c_transfer(&av7110->i2c_adap, &msgs[0], 2) != 2) { 64 if (i2c_transfer(&av7110->i2c_adap, &msgs[0], 2) != 2) {
65 dprintk(1, "dvb-ttpci: failed @ card %d, %u\n", 65 dprintk(1, "dvb-ttpci: failed @ card %d, %u\n",
66 av7110->dvb_adapter->num, reg); 66 av7110->dvb_adapter.num, reg);
67 return -EIO; 67 return -EIO;
68 } 68 }
69 *val = (msg2[0] << 8) | msg2[1]; 69 *val = (msg2[0] << 8) | msg2[1];
@@ -552,13 +552,13 @@ int av7110_init_analog_module(struct av7110 *av7110)
552 return -ENODEV; 552 return -ENODEV;
553 553
554 printk("dvb-ttpci: DVB-C analog module @ card %d detected, initializing MSP3400\n", 554 printk("dvb-ttpci: DVB-C analog module @ card %d detected, initializing MSP3400\n",
555 av7110->dvb_adapter->num); 555 av7110->dvb_adapter.num);
556 av7110->adac_type = DVB_ADAC_MSP; 556 av7110->adac_type = DVB_ADAC_MSP;
557 msleep(100); // the probing above resets the msp... 557 msleep(100); // the probing above resets the msp...
558 msp_readreg(av7110, MSP_RD_DSP, 0x001e, &version1); 558 msp_readreg(av7110, MSP_RD_DSP, 0x001e, &version1);
559 msp_readreg(av7110, MSP_RD_DSP, 0x001f, &version2); 559 msp_readreg(av7110, MSP_RD_DSP, 0x001f, &version2);
560 dprintk(1, "dvb-ttpci: @ card %d MSP3400 version 0x%04x 0x%04x\n", 560 dprintk(1, "dvb-ttpci: @ card %d MSP3400 version 0x%04x 0x%04x\n",
561 av7110->dvb_adapter->num, version1, version2); 561 av7110->dvb_adapter.num, version1, version2);
562 msp_writereg(av7110, MSP_WR_DSP, 0x0013, 0x0c00); 562 msp_writereg(av7110, MSP_WR_DSP, 0x0013, 0x0c00);
563 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone 563 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone
564 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source 564 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source
@@ -596,7 +596,7 @@ int av7110_init_analog_module(struct av7110 *av7110)
596 /* init the saa7113 */ 596 /* init the saa7113 */
597 while (*i != 0xff) { 597 while (*i != 0xff) {
598 if (i2c_writereg(av7110, 0x48, i[0], i[1]) != 1) { 598 if (i2c_writereg(av7110, 0x48, i[0], i[1]) != 1) {
599 dprintk(1, "saa7113 initialization failed @ card %d", av7110->dvb_adapter->num); 599 dprintk(1, "saa7113 initialization failed @ card %d", av7110->dvb_adapter.num);
600 break; 600 break;
601 } 601 }
602 i += 2; 602 i += 2;
@@ -726,11 +726,11 @@ static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
726{ 726{
727 struct av7110 *av7110 = (struct av7110*) dev->ext_priv; 727 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
728 728
729 if (std->id == V4L2_STD_PAL) { 729 if (std->id & V4L2_STD_PAL) {
730 av7110->vidmode = VIDEO_MODE_PAL; 730 av7110->vidmode = VIDEO_MODE_PAL;
731 av7110_set_vidmode(av7110, av7110->vidmode); 731 av7110_set_vidmode(av7110, av7110->vidmode);
732 } 732 }
733 else if (std->id == V4L2_STD_NTSC) { 733 else if (std->id & V4L2_STD_NTSC) {
734 av7110->vidmode = VIDEO_MODE_NTSC; 734 av7110->vidmode = VIDEO_MODE_NTSC;
735 av7110_set_vidmode(av7110, av7110->vidmode); 735 av7110_set_vidmode(av7110, av7110->vidmode);
736 } 736 }
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 14e963206b89..6e0f5d307c52 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -59,8 +59,12 @@ struct budget_av {
59 struct dvb_ca_en50221 ca; 59 struct dvb_ca_en50221 ca;
60}; 60};
61 61
62static int enable_ci = 0; 62/* GPIO CI Connections:
63 63 * 0 - Vcc/Reset (Reset is controlled by capacitor)
64 * 1 - Attribute Memory
65 * 2 - Card Enable (Active Low)
66 * 3 - Card Detect
67 */
64 68
65/**************************************************************************** 69/****************************************************************************
66 * INITIALIZATION 70 * INITIALIZATION
@@ -188,22 +192,35 @@ static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
188{ 192{
189 struct budget_av *budget_av = (struct budget_av *) ca->data; 193 struct budget_av *budget_av = (struct budget_av *) ca->data;
190 struct saa7146_dev *saa = budget_av->budget.dev; 194 struct saa7146_dev *saa = budget_av->budget.dev;
191 int max = 20; 195 int timeout = 50; // 5 seconds (4.4.6 Ready)
192 196
193 if (slot != 0) 197 if (slot != 0)
194 return -EINVAL; 198 return -EINVAL;
195 199
196 dprintk(1, "ciintf_slot_reset\n"); 200 dprintk(1, "ciintf_slot_reset\n");
197 201
198 /* reset the card */ 202 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */
199 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI);
200 msleep(100);
201 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO);
202 203
203 while (--max > 0 && ciintf_read_attribute_mem(ca, slot, 0) != 0x1d) 204 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); /* Vcc off */
205 msleep(2);
206 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO); /* Vcc on */
207 msleep(20); /* 20 ms Vcc settling time */
208
209 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTLO); /* enable card */
210
211 /* This should have been based on pin 16 READY of the pcmcia port,
212 * but AFAICS it is not routed to the saa7146 */
213 while (--timeout > 0 && ciintf_read_attribute_mem(ca, slot, 0) != 0x1d)
204 msleep(100); 214 msleep(100);
205 215
206 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB); 216 if (timeout <= 0)
217 {
218 printk(KERN_ERR "budget-av: cam reset failed (timeout).\n");
219 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */
220 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); /* Vcc off */
221 return -ETIMEDOUT;
222 }
223
207 return 0; 224 return 0;
208} 225}
209 226
@@ -240,7 +257,6 @@ static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open
240{ 257{
241 struct budget_av *budget_av = (struct budget_av *) ca->data; 258 struct budget_av *budget_av = (struct budget_av *) ca->data;
242 struct saa7146_dev *saa = budget_av->budget.dev; 259 struct saa7146_dev *saa = budget_av->budget.dev;
243 int cam = 0;
244 260
245 if (slot != 0) 261 if (slot != 0)
246 return -EINVAL; 262 return -EINVAL;
@@ -248,15 +264,21 @@ static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open
248 if (!budget_av->slot_status) { 264 if (!budget_av->slot_status) {
249 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); 265 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
250 udelay(1); 266 udelay(1);
251 cam = saa7146_read(saa, PSR) & MASK_06; 267 if (saa7146_read(saa, PSR) & MASK_06)
252 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO); 268 {
253 269 printk(KERN_INFO "budget-av: cam inserted\n");
254 if (cam)
255 budget_av->slot_status = 1; 270 budget_av->slot_status = 1;
271 }
272 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
256 } else if (!open) { 273 } else if (!open) {
257 saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO); 274 saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO);
258 if (ttpci_budget_debiread(&budget_av->budget, DEBICICAM, 0, 1, 0, 1) == -ETIMEDOUT) 275 if (ttpci_budget_debiread(&budget_av->budget, DEBICICAM, 0, 1, 0, 1) == -ETIMEDOUT)
276 {
277 printk(KERN_INFO "budget-av: cam ejected\n");
278 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */
279 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); /* Vcc off */
259 budget_av->slot_status = 0; 280 budget_av->slot_status = 0;
281 }
260 } 282 }
261 283
262 if (budget_av->slot_status == 1) 284 if (budget_av->slot_status == 1)
@@ -272,17 +294,11 @@ static int ciintf_init(struct budget_av *budget_av)
272 294
273 memset(&budget_av->ca, 0, sizeof(struct dvb_ca_en50221)); 295 memset(&budget_av->ca, 0, sizeof(struct dvb_ca_en50221));
274 296
275 /* setup GPIOs */ 297 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO);
276 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI); 298 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
277 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTLO); 299 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTLO);
278 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO); 300 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
279 301
280 /* Reset the card */
281 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI);
282 msleep(50);
283 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO);
284 msleep(100);
285
286 /* Enable DEBI pins */ 302 /* Enable DEBI pins */
287 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800); 303 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800);
288 304
@@ -297,13 +313,14 @@ static int ciintf_init(struct budget_av *budget_av)
297 budget_av->ca.slot_ts_enable = ciintf_slot_ts_enable; 313 budget_av->ca.slot_ts_enable = ciintf_slot_ts_enable;
298 budget_av->ca.poll_slot_status = ciintf_poll_slot_status; 314 budget_av->ca.poll_slot_status = ciintf_poll_slot_status;
299 budget_av->ca.data = budget_av; 315 budget_av->ca.data = budget_av;
300 if ((result = dvb_ca_en50221_init(budget_av->budget.dvb_adapter, 316
317 if ((result = dvb_ca_en50221_init(&budget_av->budget.dvb_adapter,
301 &budget_av->ca, 0, 1)) != 0) { 318 &budget_av->ca, 0, 1)) != 0) {
302 printk("budget_av: CI interface detected, but initialisation failed.\n"); 319 printk(KERN_ERR "budget-av: ci initialisation failed.\n");
303 goto error; 320 goto error;
304 } 321 }
305 // success! 322
306 printk("ciintf_init: CI interface initialised\n"); 323 printk(KERN_INFO "budget-av: ci interface initialised.\n");
307 budget_av->budget.ci_present = 1; 324 budget_av->budget.ci_present = 1;
308 return 0; 325 return 0;
309 326
@@ -361,8 +378,12 @@ static const u8 saa7113_tab[] = {
361static int saa7113_init(struct budget_av *budget_av) 378static int saa7113_init(struct budget_av *budget_av)
362{ 379{
363 struct budget *budget = &budget_av->budget; 380 struct budget *budget = &budget_av->budget;
381 struct saa7146_dev *saa = budget->dev;
364 const u8 *data = saa7113_tab; 382 const u8 *data = saa7113_tab;
365 383
384 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI);
385 msleep(200);
386
366 if (i2c_writereg(&budget->i2c_adap, 0x4a, 0x01, 0x08) != 1) { 387 if (i2c_writereg(&budget->i2c_adap, 0x4a, 0x01, 0x08) != 1) {
367 dprintk(1, "saa7113 not found on KNC card\n"); 388 dprintk(1, "saa7113 not found on KNC card\n");
368 return -ENODEV; 389 return -ENODEV;
@@ -697,75 +718,90 @@ static u8 read_pwm(struct budget_av *budget_av)
697 return pwm; 718 return pwm;
698} 719}
699 720
721#define SUBID_DVBS_KNC1 0x0010
722#define SUBID_DVBS_KNC1_PLUS 0x0011
723#define SUBID_DVBS_TYPHOON 0x4f56
724#define SUBID_DVBS_CINERGY1200 0x1154
725
726#define SUBID_DVBC_KNC1 0x0020
727#define SUBID_DVBC_KNC1_PLUS 0x0021
728#define SUBID_DVBC_CINERGY1200 0x1156
729
730#define SUBID_DVBT_KNC1_PLUS 0x0031
731#define SUBID_DVBT_KNC1 0x0030
732#define SUBID_DVBT_CINERGY1200 0x1157
700 733
701static void frontend_init(struct budget_av *budget_av) 734static void frontend_init(struct budget_av *budget_av)
702{ 735{
703 switch (budget_av->budget.dev->pci->subsystem_device) { 736 struct saa7146_dev * saa = budget_av->budget.dev;
704 case 0x4f56: // Typhoon/KNC1 DVB-S budget (stv0299/Philips SU1278(tsa5059)) 737 struct dvb_frontend * fe = NULL;
705 budget_av->budget.dvb_frontend = 738
706 stv0299_attach(&typhoon_config, &budget_av->budget.i2c_adap); 739 switch (saa->pci->subsystem_device) {
707 if (budget_av->budget.dvb_frontend != NULL) { 740 case SUBID_DVBS_KNC1_PLUS:
741 case SUBID_DVBC_KNC1_PLUS:
742 case SUBID_DVBT_KNC1_PLUS:
743 // Enable / PowerON Frontend
744 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTHI);
708 break; 745 break;
709 } 746 }
747
748 switch (saa->pci->subsystem_device) {
749
750 case SUBID_DVBS_KNC1:
751 case SUBID_DVBS_KNC1_PLUS:
752 case SUBID_DVBS_TYPHOON:
753 fe = stv0299_attach(&typhoon_config,
754 &budget_av->budget.i2c_adap);
710 break; 755 break;
711 756
712 case 0x0020: // KNC1 DVB-C budget (tda10021/Philips CU1216(tua6034)) 757 case SUBID_DVBS_CINERGY1200:
713 budget_av->budget.dvb_frontend = 758 fe = stv0299_attach(&cinergy_1200s_config,
714 tda10021_attach(&philips_cu1216_config, 759 &budget_av->budget.i2c_adap);
715 &budget_av->budget.i2c_adap, read_pwm(budget_av));
716 if (budget_av->budget.dvb_frontend != NULL) {
717 break;
718 }
719 break; 760 break;
720 761
721 case 0x0030: // KNC1 DVB-T budget (tda10046/Philips TU1216(tda6651tt)) 762 case SUBID_DVBC_KNC1:
722 budget_av->budget.dvb_frontend = 763 case SUBID_DVBC_KNC1_PLUS:
723 tda10046_attach(&philips_tu1216_config, &budget_av->budget.i2c_adap); 764 fe = tda10021_attach(&philips_cu1216_config,
724 if (budget_av->budget.dvb_frontend != NULL) { 765 &budget_av->budget.i2c_adap,
725 break; 766 read_pwm(budget_av));
726 }
727 break; 767 break;
728 768
729 case 0x1154: // TerraTec Cinergy 1200 DVB-S (stv0299/Philips SU1278(tsa5059)) 769 case SUBID_DVBT_KNC1:
730 budget_av->budget.dvb_frontend = 770 case SUBID_DVBT_KNC1_PLUS:
731 stv0299_attach(&cinergy_1200s_config, &budget_av->budget.i2c_adap); 771 fe = tda10046_attach(&philips_tu1216_config,
732 if (budget_av->budget.dvb_frontend != NULL) { 772 &budget_av->budget.i2c_adap);
733 break;
734 }
735 break; 773 break;
736 774
737 case 0x1156: // Terratec Cinergy 1200 DVB-C (tda10021/Philips CU1216(tua6034)) 775 case SUBID_DVBC_CINERGY1200:
738 budget_av->budget.dvb_frontend = 776 fe = tda10021_attach(&philips_cu1216_config,
739 tda10021_attach(&philips_cu1216_config, 777 &budget_av->budget.i2c_adap,
740 &budget_av->budget.i2c_adap, read_pwm(budget_av)); 778 read_pwm(budget_av));
741 if (budget_av->budget.dvb_frontend) {
742 break;
743 }
744 break; 779 break;
745 780
746 case 0x1157: // Terratec Cinergy 1200 DVB-T (tda10046/Philips TU1216(tda6651tt)) 781 case SUBID_DVBT_CINERGY1200:
747 budget_av->budget.dvb_frontend = 782 fe = tda10046_attach(&philips_tu1216_config,
748 tda10046_attach(&philips_tu1216_config, &budget_av->budget.i2c_adap); 783 &budget_av->budget.i2c_adap);
749 if (budget_av->budget.dvb_frontend) {
750 break;
751 }
752 break; 784 break;
753 } 785 }
754 786
755 if (budget_av->budget.dvb_frontend == NULL) { 787 if (fe == NULL) {
756 printk("budget_av: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", 788 printk(KERN_ERR "budget-av: A frontend driver was not found "
757 budget_av->budget.dev->pci->vendor, 789 "for device %04x/%04x subsystem %04x/%04x\n",
758 budget_av->budget.dev->pci->device, 790 saa->pci->vendor,
759 budget_av->budget.dev->pci->subsystem_vendor, 791 saa->pci->device,
760 budget_av->budget.dev->pci->subsystem_device); 792 saa->pci->subsystem_vendor,
761 } else { 793 saa->pci->subsystem_device);
762 if (dvb_register_frontend 794 return;
763 (budget_av->budget.dvb_adapter, budget_av->budget.dvb_frontend)) { 795 }
764 printk("budget-av: Frontend registration failed!\n"); 796
765 if (budget_av->budget.dvb_frontend->ops->release) 797 budget_av->budget.dvb_frontend = fe;
766 budget_av->budget.dvb_frontend->ops->release(budget_av->budget.dvb_frontend); 798
767 budget_av->budget.dvb_frontend = NULL; 799 if (dvb_register_frontend(&budget_av->budget.dvb_adapter,
768 } 800 budget_av->budget.dvb_frontend)) {
801 printk(KERN_ERR "budget-av: Frontend registration failed!\n");
802 if (budget_av->budget.dvb_frontend->ops->release)
803 budget_av->budget.dvb_frontend->ops->release(budget_av->budget.dvb_frontend);
804 budget_av->budget.dvb_frontend = NULL;
769 } 805 }
770} 806}
771 807
@@ -822,6 +858,7 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
822 858
823 memset(budget_av, 0, sizeof(struct budget_av)); 859 memset(budget_av, 0, sizeof(struct budget_av));
824 860
861 budget_av->has_saa7113 = 0;
825 budget_av->budget.ci_present = 0; 862 budget_av->budget.ci_present = 0;
826 863
827 dev->ext_priv = budget_av; 864 dev->ext_priv = budget_av;
@@ -836,10 +873,7 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
836 saa7146_write(dev, DD1_INIT, 0x07000600); 873 saa7146_write(dev, DD1_INIT, 0x07000600);
837 saa7146_write(dev, MC2, MASK_09 | MASK_25 | MASK_10 | MASK_26); 874 saa7146_write(dev, MC2, MASK_09 | MASK_25 | MASK_10 | MASK_26);
838 875
839 saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTHI); 876 if (saa7113_init(budget_av) == 0) {
840 msleep(500);
841
842 if (0 == saa7113_init(budget_av)) {
843 budget_av->has_saa7113 = 1; 877 budget_av->has_saa7113 = 1;
844 878
845 if (0 != saa7146_vv_init(dev, &vv_data)) { 879 if (0 != saa7146_vv_init(dev, &vv_data)) {
@@ -860,31 +894,26 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
860 894
861 saa7113_setinput(budget_av, 0); 895 saa7113_setinput(budget_av, 0);
862 } else { 896 } else {
863 budget_av->has_saa7113 = 0; 897 ciintf_init(budget_av);
864
865 saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTLO);
866 } 898 }
867 899
868 /* fixme: find some sane values here... */ 900 /* fixme: find some sane values here... */
869 saa7146_write(dev, PCI_BT_V1, 0x1c00101f); 901 saa7146_write(dev, PCI_BT_V1, 0x1c00101f);
870 902
871 mac = budget_av->budget.dvb_adapter->proposed_mac; 903 mac = budget_av->budget.dvb_adapter.proposed_mac;
872 if (i2c_readregs(&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) { 904 if (i2c_readregs(&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) {
873 printk("KNC1-%d: Could not read MAC from KNC1 card\n", 905 printk(KERN_ERR "KNC1-%d: Could not read MAC from KNC1 card\n",
874 budget_av->budget.dvb_adapter->num); 906 budget_av->budget.dvb_adapter.num);
875 memset(mac, 0, 6); 907 memset(mac, 0, 6);
876 } else { 908 } else {
877 printk("KNC1-%d: MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", 909 printk(KERN_INFO "KNC1-%d: MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
878 budget_av->budget.dvb_adapter->num, 910 budget_av->budget.dvb_adapter.num,
879 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 911 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
880 } 912 }
881 913
882 budget_av->budget.dvb_adapter->priv = budget_av; 914 budget_av->budget.dvb_adapter.priv = budget_av;
883 frontend_init(budget_av); 915 frontend_init(budget_av);
884 916
885 if (enable_ci)
886 ciintf_init(budget_av);
887
888 return 0; 917 return 0;
889} 918}
890 919
@@ -963,14 +992,21 @@ static struct saa7146_extension budget_extension;
963MAKE_BUDGET_INFO(knc1s, "KNC1 DVB-S", BUDGET_KNC1S); 992MAKE_BUDGET_INFO(knc1s, "KNC1 DVB-S", BUDGET_KNC1S);
964MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C); 993MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C);
965MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T); 994MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T);
995MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP);
996MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP);
997MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP);
966MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S); 998MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S);
967MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C); 999MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C);
968MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T); 1000MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T);
969 1001
970static struct pci_device_id pci_tbl[] = { 1002static struct pci_device_id pci_tbl[] = {
971 MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x4f56), 1003 MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x4f56),
1004 MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x0010),
1005 MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011),
972 MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020), 1006 MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020),
1007 MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021),
973 MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030), 1008 MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030),
1009 MAKE_EXTENSION_PCI(knc1tp, 0x1894, 0x0031),
974 MAKE_EXTENSION_PCI(cin1200s, 0x153b, 0x1154), 1010 MAKE_EXTENSION_PCI(cin1200s, 0x153b, 0x1154),
975 MAKE_EXTENSION_PCI(cin1200c, 0x153b, 0x1156), 1011 MAKE_EXTENSION_PCI(cin1200c, 0x153b, 0x1156),
976 MAKE_EXTENSION_PCI(cin1200t, 0x153b, 0x1157), 1012 MAKE_EXTENSION_PCI(cin1200t, 0x153b, 0x1157),
@@ -1010,5 +1046,3 @@ MODULE_LICENSE("GPL");
1010MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others"); 1046MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
1011MODULE_DESCRIPTION("driver for the SAA7146 based so-called " 1047MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
1012 "budget PCI DVB w/ analog input and CI-module (e.g. the KNC cards)"); 1048 "budget PCI DVB w/ analog input and CI-module (e.g. the KNC cards)");
1013module_param_named(enable_ci, enable_ci, int, 0644);
1014MODULE_PARM_DESC(enable_ci, "Turn on/off CI module (default:off).");
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 521111be3558..dce116111376 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -395,7 +395,7 @@ static int ciintf_init(struct budget_ci *budget_ci)
395 budget_ci->ca.slot_shutdown = ciintf_slot_shutdown; 395 budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
396 budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable; 396 budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
397 budget_ci->ca.data = budget_ci; 397 budget_ci->ca.data = budget_ci;
398 if ((result = dvb_ca_en50221_init(budget_ci->budget.dvb_adapter, 398 if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
399 &budget_ci->ca, 399 &budget_ci->ca,
400 DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE | 400 DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
401 DVB_CA_EN50221_FLAG_IRQ_FR | 401 DVB_CA_EN50221_FLAG_IRQ_FR |
@@ -881,7 +881,7 @@ static void frontend_init(struct budget_ci *budget_ci)
881 budget_ci->budget.dev->pci->subsystem_device); 881 budget_ci->budget.dev->pci->subsystem_device);
882 } else { 882 } else {
883 if (dvb_register_frontend 883 if (dvb_register_frontend
884 (budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) { 884 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
885 printk("budget-ci: Frontend registration failed!\n"); 885 printk("budget-ci: Frontend registration failed!\n");
886 if (budget_ci->budget.dvb_frontend->ops->release) 886 if (budget_ci->budget.dvb_frontend->ops->release)
887 budget_ci->budget.dvb_frontend->ops->release(budget_ci->budget.dvb_frontend); 887 budget_ci->budget.dvb_frontend->ops->release(budget_ci->budget.dvb_frontend);
@@ -916,7 +916,7 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
916 916
917 ciintf_init(budget_ci); 917 ciintf_init(budget_ci);
918 918
919 budget_ci->budget.dvb_adapter->priv = budget_ci; 919 budget_ci->budget.dvb_adapter.priv = budget_ci;
920 frontend_init(budget_ci); 920 frontend_init(budget_ci);
921 921
922 return 0; 922 return 0;
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index 93a9b40917e4..0498a055a4cd 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -298,7 +298,7 @@ static int budget_register(struct budget *budget)
298 budget->dmxdev.demux = &dvbdemux->dmx; 298 budget->dmxdev.demux = &dvbdemux->dmx;
299 budget->dmxdev.capabilities = 0; 299 budget->dmxdev.capabilities = 0;
300 300
301 dvb_dmxdev_init(&budget->dmxdev, budget->dvb_adapter); 301 dvb_dmxdev_init(&budget->dmxdev, &budget->dvb_adapter);
302 302
303 budget->hw_frontend.source = DMX_FRONTEND_0; 303 budget->hw_frontend.source = DMX_FRONTEND_0;
304 304
@@ -316,7 +316,7 @@ static int budget_register(struct budget *budget)
316 if (ret < 0) 316 if (ret < 0)
317 return ret; 317 return ret;
318 318
319 dvb_net_init(budget->dvb_adapter, &budget->dvb_net, &dvbdemux->dmx); 319 dvb_net_init(&budget->dvb_adapter, &budget->dvb_net, &dvbdemux->dmx);
320 320
321 return 0; 321 return 0;
322} 322}
@@ -385,11 +385,11 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
385 strcpy(budget->i2c_adap.name, budget->card->name); 385 strcpy(budget->i2c_adap.name, budget->card->name);
386 386
387 if (i2c_add_adapter(&budget->i2c_adap) < 0) { 387 if (i2c_add_adapter(&budget->i2c_adap) < 0) {
388 dvb_unregister_adapter(budget->dvb_adapter); 388 dvb_unregister_adapter(&budget->dvb_adapter);
389 return -ENOMEM; 389 return -ENOMEM;
390 } 390 }
391 391
392 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter->proposed_mac); 392 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac);
393 393
394 if (NULL == 394 if (NULL ==
395 (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, length, &budget->pt))) { 395 (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, length, &budget->pt))) {
@@ -417,7 +417,7 @@ err:
417 417
418 vfree(budget->grabbing); 418 vfree(budget->grabbing);
419 419
420 dvb_unregister_adapter(budget->dvb_adapter); 420 dvb_unregister_adapter(&budget->dvb_adapter);
421 421
422 return ret; 422 return ret;
423} 423}
@@ -432,7 +432,7 @@ int ttpci_budget_deinit(struct budget *budget)
432 432
433 i2c_del_adapter(&budget->i2c_adap); 433 i2c_del_adapter(&budget->i2c_adap);
434 434
435 dvb_unregister_adapter(budget->dvb_adapter); 435 dvb_unregister_adapter(&budget->dvb_adapter);
436 436
437 tasklet_kill(&budget->vpe_tasklet); 437 tasklet_kill(&budget->vpe_tasklet);
438 438
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index 5d524a4f213f..8142e26b47f5 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -453,7 +453,7 @@ static void frontend_init(struct budget_patch* budget)
453 budget->dev->pci->subsystem_vendor, 453 budget->dev->pci->subsystem_vendor,
454 budget->dev->pci->subsystem_device); 454 budget->dev->pci->subsystem_device);
455 } else { 455 } else {
456 if (dvb_register_frontend(budget->dvb_adapter, budget->dvb_frontend)) { 456 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) {
457 printk("budget-av: Frontend registration failed!\n"); 457 printk("budget-av: Frontend registration failed!\n");
458 if (budget->dvb_frontend->ops->release) 458 if (budget->dvb_frontend->ops->release)
459 budget->dvb_frontend->ops->release(budget->dvb_frontend); 459 budget->dvb_frontend->ops->release(budget->dvb_frontend);
@@ -702,7 +702,7 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
702 702
703 dev->ext_priv = budget; 703 dev->ext_priv = budget;
704 704
705 budget->dvb_adapter->priv = budget; 705 budget->dvb_adapter.priv = budget;
706 frontend_init(budget); 706 frontend_init(budget);
707 707
708 return 0; 708 return 0;
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 5e6a10f4ad95..083fd44e5f90 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -468,7 +468,7 @@ static void frontend_init(struct budget *budget)
468 budget->dev->pci->subsystem_vendor, 468 budget->dev->pci->subsystem_vendor,
469 budget->dev->pci->subsystem_device); 469 budget->dev->pci->subsystem_device);
470 } else { 470 } else {
471 if (dvb_register_frontend(budget->dvb_adapter, budget->dvb_frontend)) { 471 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) {
472 printk("budget: Frontend registration failed!\n"); 472 printk("budget: Frontend registration failed!\n");
473 if (budget->dvb_frontend->ops->release) 473 if (budget->dvb_frontend->ops->release)
474 budget->dvb_frontend->ops->release(budget->dvb_frontend); 474 budget->dvb_frontend->ops->release(budget->dvb_frontend);
@@ -497,7 +497,7 @@ static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_
497 return err; 497 return err;
498 } 498 }
499 499
500 budget->dvb_adapter->priv = budget; 500 budget->dvb_adapter.priv = budget;
501 frontend_init(budget); 501 frontend_init(budget);
502 502
503 return 0; 503 return 0;
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
index 10bd41f0363b..c6ef496ba70a 100644
--- a/drivers/media/dvb/ttpci/budget.h
+++ b/drivers/media/dvb/ttpci/budget.h
@@ -64,7 +64,7 @@ struct budget {
64 64
65 spinlock_t debilock; 65 spinlock_t debilock;
66 66
67 struct dvb_adapter *dvb_adapter; 67 struct dvb_adapter dvb_adapter;
68 struct dvb_frontend *dvb_frontend; 68 struct dvb_frontend *dvb_frontend;
69 void *priv; 69 void *priv;
70}; 70};
@@ -92,6 +92,9 @@ static struct saa7146_pci_extension_data x_var = { \
92#define BUDGET_KNC1S 8 92#define BUDGET_KNC1S 8
93#define BUDGET_KNC1C 9 93#define BUDGET_KNC1C 9
94#define BUDGET_KNC1T 10 94#define BUDGET_KNC1T 10
95#define BUDGET_KNC1SP 11
96#define BUDGET_KNC1CP 12
97#define BUDGET_KNC1TP 13
95 98
96#define BUDGET_VIDEO_PORTA 0 99#define BUDGET_VIDEO_PORTA 0
97#define BUDGET_VIDEO_PORTB 1 100#define BUDGET_VIDEO_PORTB 1
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 4c046ece883a..afa0e7a0e506 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -84,7 +84,7 @@ struct ttusb {
84 struct semaphore semi2c; 84 struct semaphore semi2c;
85 struct semaphore semusb; 85 struct semaphore semusb;
86 86
87 struct dvb_adapter *adapter; 87 struct dvb_adapter adapter;
88 struct usb_device *dev; 88 struct usb_device *dev;
89 89
90 struct i2c_adapter i2c_adap; 90 struct i2c_adapter i2c_adap;
@@ -1065,7 +1065,7 @@ static int alps_tdmb7_pll_set(struct dvb_frontend* fe, struct dvb_frontend_param
1065 return 0; 1065 return 0;
1066} 1066}
1067 1067
1068struct cx22700_config alps_tdmb7_config = { 1068static struct cx22700_config alps_tdmb7_config = {
1069 .demod_address = 0x43, 1069 .demod_address = 0x43,
1070 .pll_set = alps_tdmb7_pll_set, 1070 .pll_set = alps_tdmb7_pll_set,
1071}; 1071};
@@ -1412,7 +1412,7 @@ static void frontend_init(struct ttusb* ttusb)
1412 le16_to_cpu(ttusb->dev->descriptor.idVendor), 1412 le16_to_cpu(ttusb->dev->descriptor.idVendor),
1413 le16_to_cpu(ttusb->dev->descriptor.idProduct)); 1413 le16_to_cpu(ttusb->dev->descriptor.idProduct));
1414 } else { 1414 } else {
1415 if (dvb_register_frontend(ttusb->adapter, ttusb->fe)) { 1415 if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) {
1416 printk("dvb-ttusb-budget: Frontend registration failed!\n"); 1416 printk("dvb-ttusb-budget: Frontend registration failed!\n");
1417 if (ttusb->fe->ops->release) 1417 if (ttusb->fe->ops->release)
1418 ttusb->fe->ops->release(ttusb->fe); 1418 ttusb->fe->ops->release(ttusb->fe);
@@ -1462,7 +1462,7 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1462 up(&ttusb->semi2c); 1462 up(&ttusb->semi2c);
1463 1463
1464 dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE); 1464 dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE);
1465 ttusb->adapter->priv = ttusb; 1465 ttusb->adapter.priv = ttusb;
1466 1466
1467 /* i2c */ 1467 /* i2c */
1468 memset(&ttusb->i2c_adap, 0, sizeof(struct i2c_adapter)); 1468 memset(&ttusb->i2c_adap, 0, sizeof(struct i2c_adapter));
@@ -1481,7 +1481,7 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1481 1481
1482 result = i2c_add_adapter(&ttusb->i2c_adap); 1482 result = i2c_add_adapter(&ttusb->i2c_adap);
1483 if (result) { 1483 if (result) {
1484 dvb_unregister_adapter (ttusb->adapter); 1484 dvb_unregister_adapter (&ttusb->adapter);
1485 return result; 1485 return result;
1486 } 1486 }
1487 1487
@@ -1503,7 +1503,7 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1503 if ((result = dvb_dmx_init(&ttusb->dvb_demux)) < 0) { 1503 if ((result = dvb_dmx_init(&ttusb->dvb_demux)) < 0) {
1504 printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result); 1504 printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result);
1505 i2c_del_adapter(&ttusb->i2c_adap); 1505 i2c_del_adapter(&ttusb->i2c_adap);
1506 dvb_unregister_adapter (ttusb->adapter); 1506 dvb_unregister_adapter (&ttusb->adapter);
1507 return -ENODEV; 1507 return -ENODEV;
1508 } 1508 }
1509//FIXME dmxdev (nur WAS?) 1509//FIXME dmxdev (nur WAS?)
@@ -1511,21 +1511,21 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1511 ttusb->dmxdev.demux = &ttusb->dvb_demux.dmx; 1511 ttusb->dmxdev.demux = &ttusb->dvb_demux.dmx;
1512 ttusb->dmxdev.capabilities = 0; 1512 ttusb->dmxdev.capabilities = 0;
1513 1513
1514 if ((result = dvb_dmxdev_init(&ttusb->dmxdev, ttusb->adapter)) < 0) { 1514 if ((result = dvb_dmxdev_init(&ttusb->dmxdev, &ttusb->adapter)) < 0) {
1515 printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n", 1515 printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n",
1516 result); 1516 result);
1517 dvb_dmx_release(&ttusb->dvb_demux); 1517 dvb_dmx_release(&ttusb->dvb_demux);
1518 i2c_del_adapter(&ttusb->i2c_adap); 1518 i2c_del_adapter(&ttusb->i2c_adap);
1519 dvb_unregister_adapter (ttusb->adapter); 1519 dvb_unregister_adapter (&ttusb->adapter);
1520 return -ENODEV; 1520 return -ENODEV;
1521 } 1521 }
1522 1522
1523 if (dvb_net_init(ttusb->adapter, &ttusb->dvbnet, &ttusb->dvb_demux.dmx)) { 1523 if (dvb_net_init(&ttusb->adapter, &ttusb->dvbnet, &ttusb->dvb_demux.dmx)) {
1524 printk("ttusb_dvb: dvb_net_init failed!\n"); 1524 printk("ttusb_dvb: dvb_net_init failed!\n");
1525 dvb_dmxdev_release(&ttusb->dmxdev); 1525 dvb_dmxdev_release(&ttusb->dmxdev);
1526 dvb_dmx_release(&ttusb->dvb_demux); 1526 dvb_dmx_release(&ttusb->dvb_demux);
1527 i2c_del_adapter(&ttusb->i2c_adap); 1527 i2c_del_adapter(&ttusb->i2c_adap);
1528 dvb_unregister_adapter (ttusb->adapter); 1528 dvb_unregister_adapter (&ttusb->adapter);
1529 return -ENODEV; 1529 return -ENODEV;
1530 } 1530 }
1531 1531
@@ -1559,7 +1559,7 @@ static void ttusb_disconnect(struct usb_interface *intf)
1559 dvb_dmx_release(&ttusb->dvb_demux); 1559 dvb_dmx_release(&ttusb->dvb_demux);
1560 if (ttusb->fe != NULL) dvb_unregister_frontend(ttusb->fe); 1560 if (ttusb->fe != NULL) dvb_unregister_frontend(ttusb->fe);
1561 i2c_del_adapter(&ttusb->i2c_adap); 1561 i2c_del_adapter(&ttusb->i2c_adap);
1562 dvb_unregister_adapter(ttusb->adapter); 1562 dvb_unregister_adapter(&ttusb->adapter);
1563 1563
1564 ttusb_free_iso_urbs(ttusb); 1564 ttusb_free_iso_urbs(ttusb);
1565 1565
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 64e771bd8907..505bdaff5a7e 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -98,7 +98,7 @@ struct ttusb_dec {
98 int can_playback; 98 int can_playback;
99 99
100 /* DVB bits */ 100 /* DVB bits */
101 struct dvb_adapter *adapter; 101 struct dvb_adapter adapter;
102 struct dmxdev dmxdev; 102 struct dmxdev dmxdev;
103 struct dvb_demux demux; 103 struct dvb_demux demux;
104 struct dmx_frontend frontend; 104 struct dmx_frontend frontend;
@@ -1435,7 +1435,7 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1435 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__, 1435 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__,
1436 result); 1436 result);
1437 1437
1438 dvb_unregister_adapter(dec->adapter); 1438 dvb_unregister_adapter(&dec->adapter);
1439 1439
1440 return result; 1440 return result;
1441 } 1441 }
@@ -1444,12 +1444,12 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1444 dec->dmxdev.demux = &dec->demux.dmx; 1444 dec->dmxdev.demux = &dec->demux.dmx;
1445 dec->dmxdev.capabilities = 0; 1445 dec->dmxdev.capabilities = 0;
1446 1446
1447 if ((result = dvb_dmxdev_init(&dec->dmxdev, dec->adapter)) < 0) { 1447 if ((result = dvb_dmxdev_init(&dec->dmxdev, &dec->adapter)) < 0) {
1448 printk("%s: dvb_dmxdev_init failed: error %d\n", 1448 printk("%s: dvb_dmxdev_init failed: error %d\n",
1449 __FUNCTION__, result); 1449 __FUNCTION__, result);
1450 1450
1451 dvb_dmx_release(&dec->demux); 1451 dvb_dmx_release(&dec->demux);
1452 dvb_unregister_adapter(dec->adapter); 1452 dvb_unregister_adapter(&dec->adapter);
1453 1453
1454 return result; 1454 return result;
1455 } 1455 }
@@ -1463,7 +1463,7 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1463 1463
1464 dvb_dmxdev_release(&dec->dmxdev); 1464 dvb_dmxdev_release(&dec->dmxdev);
1465 dvb_dmx_release(&dec->demux); 1465 dvb_dmx_release(&dec->demux);
1466 dvb_unregister_adapter(dec->adapter); 1466 dvb_unregister_adapter(&dec->adapter);
1467 1467
1468 return result; 1468 return result;
1469 } 1469 }
@@ -1476,12 +1476,12 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1476 dec->demux.dmx.remove_frontend(&dec->demux.dmx, &dec->frontend); 1476 dec->demux.dmx.remove_frontend(&dec->demux.dmx, &dec->frontend);
1477 dvb_dmxdev_release(&dec->dmxdev); 1477 dvb_dmxdev_release(&dec->dmxdev);
1478 dvb_dmx_release(&dec->demux); 1478 dvb_dmx_release(&dec->demux);
1479 dvb_unregister_adapter(dec->adapter); 1479 dvb_unregister_adapter(&dec->adapter);
1480 1480
1481 return result; 1481 return result;
1482 } 1482 }
1483 1483
1484 dvb_net_init(dec->adapter, &dec->dvb_net, &dec->demux.dmx); 1484 dvb_net_init(&dec->adapter, &dec->dvb_net, &dec->demux.dmx);
1485 1485
1486 return 0; 1486 return 0;
1487} 1487}
@@ -1496,7 +1496,7 @@ static void ttusb_dec_exit_dvb(struct ttusb_dec *dec)
1496 dvb_dmxdev_release(&dec->dmxdev); 1496 dvb_dmxdev_release(&dec->dmxdev);
1497 dvb_dmx_release(&dec->demux); 1497 dvb_dmx_release(&dec->demux);
1498 if (dec->fe) dvb_unregister_frontend(dec->fe); 1498 if (dec->fe) dvb_unregister_frontend(dec->fe);
1499 dvb_unregister_adapter(dec->adapter); 1499 dvb_unregister_adapter(&dec->adapter);
1500} 1500}
1501 1501
1502static void ttusb_dec_exit_rc(struct ttusb_dec *dec) 1502static void ttusb_dec_exit_rc(struct ttusb_dec *dec)
@@ -1565,15 +1565,15 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
1565 } 1565 }
1566} 1566}
1567 1567
1568int fe_send_command(struct dvb_frontend* fe, const u8 command, 1568static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1569 int param_length, const u8 params[], 1569 int param_length, const u8 params[],
1570 int *result_length, u8 cmd_result[]) 1570 int *result_length, u8 cmd_result[])
1571{ 1571{
1572 struct ttusb_dec* dec = (struct ttusb_dec*) fe->dvb->priv; 1572 struct ttusb_dec* dec = (struct ttusb_dec*) fe->dvb->priv;
1573 return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result); 1573 return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1574} 1574}
1575 1575
1576struct ttusbdecfe_config fe_config = { 1576static struct ttusbdecfe_config fe_config = {
1577 .send_command = fe_send_command 1577 .send_command = fe_send_command
1578}; 1578};
1579 1579
@@ -1620,7 +1620,7 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1620 } 1620 }
1621 ttusb_dec_init_dvb(dec); 1621 ttusb_dec_init_dvb(dec);
1622 1622
1623 dec->adapter->priv = dec; 1623 dec->adapter.priv = dec;
1624 switch (le16_to_cpu(id->idProduct)) { 1624 switch (le16_to_cpu(id->idProduct)) {
1625 case 0x1006: 1625 case 0x1006:
1626 dec->fe = ttusbdecfe_dvbs_attach(&fe_config); 1626 dec->fe = ttusbdecfe_dvbs_attach(&fe_config);
@@ -1637,7 +1637,7 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1637 le16_to_cpu(dec->udev->descriptor.idVendor), 1637 le16_to_cpu(dec->udev->descriptor.idVendor),
1638 le16_to_cpu(dec->udev->descriptor.idProduct)); 1638 le16_to_cpu(dec->udev->descriptor.idProduct));
1639 } else { 1639 } else {
1640 if (dvb_register_frontend(dec->adapter, dec->fe)) { 1640 if (dvb_register_frontend(&dec->adapter, dec->fe)) {
1641 printk("budget-ci: Frontend registration failed!\n"); 1641 printk("budget-ci: Frontend registration failed!\n");
1642 if (dec->fe->ops->release) 1642 if (dec->fe->ops->release)
1643 dec->fe->ops->release(dec->fe); 1643 dec->fe->ops->release(dec->fe);
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index d3dd4228b72d..f9383e7f34ff 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -7,6 +7,19 @@ menu "Video For Linux"
7 7
8comment "Video Adapters" 8comment "Video Adapters"
9 9
10config CONFIG_TUNER_MULTI_I2C
11 bool "Enable support for multiple I2C devices on Video Adapters (EXPERIMENTAL)"
12 depends on VIDEO_DEV && EXPERIMENTAL
13 ---help---
14 Some video adapters have more than one tuner inside. This patch
15 enables support for using more than one tuner. This is required
16 for some cards to allow tunning both video and radio.
17 It also improves I2C autodetection for these cards.
18
19 Only few tuners currently is supporting this. More to come.
20
21 It is safe to say 'Y' here even if your card has only one I2C tuner.
22
10config VIDEO_BT848 23config VIDEO_BT848
11 tristate "BT848 Video For Linux" 24 tristate "BT848 Video For Linux"
12 depends on VIDEO_DEV && PCI && I2C 25 depends on VIDEO_DEV && PCI && I2C
@@ -240,6 +253,7 @@ config VIDEO_SAA7134
240 select VIDEO_BUF 253 select VIDEO_BUF
241 select VIDEO_IR 254 select VIDEO_IR
242 select VIDEO_TUNER 255 select VIDEO_TUNER
256 select CRC32
243 ---help--- 257 ---help---
244 This is a video4linux driver for Philips SAA7130/7134 based 258 This is a video4linux driver for Philips SAA7130/7134 based
245 TV cards. 259 TV cards.
@@ -329,6 +343,7 @@ config VIDEO_CX88_DVB
329 select VIDEO_BUF_DVB 343 select VIDEO_BUF_DVB
330 select DVB_MT352 344 select DVB_MT352
331 select DVB_OR51132 345 select DVB_OR51132
346 select DVB_CX22702
332 ---help--- 347 ---help---
333 This adds support for DVB/ATSC cards based on the 348 This adds support for DVB/ATSC cards based on the
334 Connexant 2388x chip. 349 Connexant 2388x chip.
diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c
index 80254caa444c..48989eda2400 100644
--- a/drivers/media/video/adv7170.c
+++ b/drivers/media/video/adv7170.c
@@ -384,22 +384,14 @@ static unsigned short normal_i2c[] =
384 I2C_ADV7171 >> 1, (I2C_ADV7171 >> 1) + 1, 384 I2C_ADV7171 >> 1, (I2C_ADV7171 >> 1) + 1,
385 I2C_CLIENT_END 385 I2C_CLIENT_END
386}; 386};
387static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
388 387
389static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 388static unsigned short ignore = I2C_CLIENT_END;
390static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
391static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
392static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
393static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
394 389
395static struct i2c_client_address_data addr_data = { 390static struct i2c_client_address_data addr_data = {
396 .normal_i2c = normal_i2c, 391 .normal_i2c = normal_i2c,
397 .normal_i2c_range = normal_i2c_range, 392 .probe = &ignore,
398 .probe = probe, 393 .ignore = &ignore,
399 .probe_range = probe_range, 394 .force = &ignore,
400 .ignore = ignore,
401 .ignore_range = ignore_range,
402 .force = force
403}; 395};
404 396
405static struct i2c_driver i2c_driver_adv7170; 397static struct i2c_driver i2c_driver_adv7170;
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index 95d0974b0ab5..f898b6586374 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -434,22 +434,14 @@ static unsigned short normal_i2c[] =
434 I2C_ADV7176 >> 1, (I2C_ADV7176 >> 1) + 1, 434 I2C_ADV7176 >> 1, (I2C_ADV7176 >> 1) + 1,
435 I2C_CLIENT_END 435 I2C_CLIENT_END
436}; 436};
437static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
438 437
439static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 438static unsigned short ignore = I2C_CLIENT_END;
440static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
441static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
442static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
443static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
444 439
445static struct i2c_client_address_data addr_data = { 440static struct i2c_client_address_data addr_data = {
446 .normal_i2c = normal_i2c, 441 .normal_i2c = normal_i2c,
447 .normal_i2c_range = normal_i2c_range, 442 .probe = &ignore,
448 .probe = probe, 443 .ignore = &ignore,
449 .probe_range = probe_range, 444 .force = &ignore,
450 .ignore = ignore,
451 .ignore_range = ignore_range,
452 .force = force
453}; 445};
454 446
455static struct i2c_driver i2c_driver_adv7175; 447static struct i2c_driver i2c_driver_adv7175;
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index cf0db2554a80..8733588f6db3 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -500,22 +500,14 @@ static unsigned short normal_i2c[] = {
500 I2C_BT819 >> 1, 500 I2C_BT819 >> 1,
501 I2C_CLIENT_END, 501 I2C_CLIENT_END,
502}; 502};
503static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
504 503
505static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 504static unsigned short ignore = I2C_CLIENT_END;
506static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
507static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
508static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
509static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
510 505
511static struct i2c_client_address_data addr_data = { 506static struct i2c_client_address_data addr_data = {
512 .normal_i2c = normal_i2c, 507 .normal_i2c = normal_i2c,
513 .normal_i2c_range = normal_i2c_range, 508 .probe = &ignore,
514 .probe = probe, 509 .ignore = &ignore,
515 .probe_range = probe_range, 510 .force = &ignore,
516 .ignore = ignore,
517 .ignore_range = ignore_range,
518 .force = force
519}; 511};
520 512
521static struct i2c_driver i2c_driver_bt819; 513static struct i2c_driver i2c_driver_bt819;
diff --git a/drivers/media/video/bt832.c b/drivers/media/video/bt832.c
index efe605a113a1..9a642c7de545 100644
--- a/drivers/media/video/bt832.c
+++ b/drivers/media/video/bt832.c
@@ -6,7 +6,7 @@
6 It outputs an 8-bit 4:2:2 YUV or YCrCb video signal which can be directly 6 It outputs an 8-bit 4:2:2 YUV or YCrCb video signal which can be directly
7 connected to bt848/bt878 GPIO pins on this purpose. 7 connected to bt848/bt878 GPIO pins on this purpose.
8 (see: VLSI Vision Ltd. www.vvl.co.uk for camera datasheets) 8 (see: VLSI Vision Ltd. www.vvl.co.uk for camera datasheets)
9 9
10 Supported Cards: 10 Supported Cards:
11 - Pixelview Rev.4E: 0x8a 11 - Pixelview Rev.4E: 0x8a
12 GPIO 0x400000 toggles Bt832 RESET, and the chip changes to i2c 0x88 ! 12 GPIO 0x400000 toggles Bt832 RESET, and the chip changes to i2c 0x88 !
@@ -31,16 +31,16 @@
31#include <linux/errno.h> 31#include <linux/errno.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33 33
34#include "id.h" 34#include <media/audiochip.h>
35#include "audiochip.h" 35#include <media/id.h>
36#include "bttv.h" 36#include "bttv.h"
37#include "bt832.h" 37#include "bt832.h"
38 38
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40 40
41/* Addresses to scan */ 41/* Addresses to scan */
42static unsigned short normal_i2c[] = {I2C_CLIENT_END}; 42static unsigned short normal_i2c[] = { I2C_BT832_ALT1>>1, I2C_BT832_ALT2>>1,
43static unsigned short normal_i2c_range[] = {I2C_BT832_ALT1>>1,I2C_BT832_ALT2>>1,I2C_CLIENT_END}; 43 I2C_CLIENT_END };
44I2C_CLIENT_INSMOD; 44I2C_CLIENT_INSMOD;
45 45
46/* ---------------------------------------------------------------------- */ 46/* ---------------------------------------------------------------------- */
@@ -95,7 +95,7 @@ int bt832_init(struct i2c_client *i2c_client_s)
95 95
96 buf=kmalloc(65,GFP_KERNEL); 96 buf=kmalloc(65,GFP_KERNEL);
97 bt832_hexdump(i2c_client_s,buf); 97 bt832_hexdump(i2c_client_s,buf);
98 98
99 if(buf[0x40] != 0x31) { 99 if(buf[0x40] != 0x31) {
100 printk("bt832: this i2c chip is no bt832 (id=%02x). Detaching.\n",buf[0x40]); 100 printk("bt832: this i2c chip is no bt832 (id=%02x). Detaching.\n",buf[0x40]);
101 kfree(buf); 101 kfree(buf);
@@ -135,7 +135,7 @@ int bt832_init(struct i2c_client *i2c_client_s)
135 buf[1]= 0x27 & (~0x01); // Default | !skip 135 buf[1]= 0x27 & (~0x01); // Default | !skip
136 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) 136 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
137 printk("bt832: i2c i/o error EO: rc == %d (should be 2)\n",rc); 137 printk("bt832: i2c i/o error EO: rc == %d (should be 2)\n",rc);
138 138
139 bt832_hexdump(i2c_client_s,buf); 139 bt832_hexdump(i2c_client_s,buf);
140 140
141#if 0 141#if 0
@@ -168,8 +168,7 @@ int bt832_init(struct i2c_client *i2c_client_s)
168 168
169 169
170 170
171static int bt832_attach(struct i2c_adapter *adap, int addr, 171static int bt832_attach(struct i2c_adapter *adap, int addr, int kind)
172 unsigned short flags, int kind)
173{ 172{
174 struct bt832 *t; 173 struct bt832 *t;
175 174
@@ -184,27 +183,32 @@ static int bt832_attach(struct i2c_adapter *adap, int addr,
184 return -ENOMEM; 183 return -ENOMEM;
185 memset(t,0,sizeof(*t)); 184 memset(t,0,sizeof(*t));
186 t->client = client_template; 185 t->client = client_template;
187 t->client.data = t; 186 i2c_set_clientdata(&t->client, t);
188 i2c_attach_client(&t->client); 187 i2c_attach_client(&t->client);
189 188
190 if(! bt832_init(&t->client)) { 189 if(! bt832_init(&t->client)) {
191 bt832_detach(&t->client); 190 bt832_detach(&t->client);
192 return -1; 191 return -1;
193 } 192 }
194 193
195 return 0; 194 return 0;
196} 195}
197 196
198static int bt832_probe(struct i2c_adapter *adap) 197static int bt832_probe(struct i2c_adapter *adap)
199{ 198{
199#ifdef I2C_CLASS_TV_ANALOG
200 if (adap->class & I2C_CLASS_TV_ANALOG) 200 if (adap->class & I2C_CLASS_TV_ANALOG)
201 return i2c_probe(adap, &addr_data, bt832_attach); 201 return i2c_probe(adap, &addr_data, bt832_attach);
202#else
203 if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848))
204 return i2c_probe(adap, &addr_data, bt832_attach);
205#endif
202 return 0; 206 return 0;
203} 207}
204 208
205static int bt832_detach(struct i2c_client *client) 209static int bt832_detach(struct i2c_client *client)
206{ 210{
207 struct bt832 *t = (struct bt832*)client->data; 211 struct bt832 *t = i2c_get_clientdata(client);
208 212
209 printk("bt832: detach.\n"); 213 printk("bt832: detach.\n");
210 i2c_detach_client(client); 214 i2c_detach_client(client);
@@ -215,7 +219,7 @@ static int bt832_detach(struct i2c_client *client)
215static int 219static int
216bt832_command(struct i2c_client *client, unsigned int cmd, void *arg) 220bt832_command(struct i2c_client *client, unsigned int cmd, void *arg)
217{ 221{
218 struct bt832 *t = (struct bt832*)client->data; 222 struct bt832 *t = i2c_get_clientdata(client);
219 223
220 printk("bt832: command %x\n",cmd); 224 printk("bt832: command %x\n",cmd);
221 225
@@ -249,19 +253,18 @@ static struct i2c_driver driver = {
249}; 253};
250static struct i2c_client client_template = 254static struct i2c_client client_template =
251{ 255{
252 .name = "bt832", 256 I2C_DEVNAME("bt832"),
253 .flags = I2C_CLIENT_ALLOW_USE, 257 .flags = I2C_CLIENT_ALLOW_USE,
254 .driver = &driver, 258 .driver = &driver,
255}; 259};
256 260
257 261
258int bt832_init_module(void) 262static int __init bt832_init_module(void)
259{ 263{
260 i2c_add_driver(&driver); 264 return i2c_add_driver(&driver);
261 return 0;
262} 265}
263 266
264static void bt832_cleanup_module(void) 267static void __exit bt832_cleanup_module(void)
265{ 268{
266 i2c_del_driver(&driver); 269 i2c_del_driver(&driver);
267} 270}
@@ -269,3 +272,10 @@ static void bt832_cleanup_module(void)
269module_init(bt832_init_module); 272module_init(bt832_init_module);
270module_exit(bt832_cleanup_module); 273module_exit(bt832_cleanup_module);
271 274
275/*
276 * Overrides for Emacs so that we follow Linus's tabbing style.
277 * ---------------------------------------------------------------------------
278 * Local variables:
279 * c-basic-offset: 8
280 * End:
281 */
diff --git a/drivers/media/video/bt832.h b/drivers/media/video/bt832.h
index 7a98c06e0e34..9b6a8d2c96b5 100644
--- a/drivers/media/video/bt832.h
+++ b/drivers/media/video/bt832.h
@@ -1,6 +1,6 @@
1/* Bt832 CMOS Camera Video Processor (VP) 1/* Bt832 CMOS Camera Video Processor (VP)
2 2
3 The Bt832 CMOS Camera Video Processor chip connects a Quartsight CMOS 3 The Bt832 CMOS Camera Video Processor chip connects a Quartsight CMOS
4 color digital camera directly to video capture devices via an 8-bit, 4 color digital camera directly to video capture devices via an 8-bit,
5 4:2:2 YUV or YCrCb video interface. 5 4:2:2 YUV or YCrCb video interface.
6 6
@@ -85,7 +85,7 @@
85#define BT832_DEVICE_ID 63 85#define BT832_DEVICE_ID 63
86# define BT832_DEVICE_ID__31 0x31 // Bt832 has ID 0x31 86# define BT832_DEVICE_ID__31 0x31 // Bt832 has ID 0x31
87 87
88/* STMicroelectronivcs VV5404 camera module 88/* STMicroelectronivcs VV5404 camera module
89 i2c: 0x20: sensor address 89 i2c: 0x20: sensor address
90 i2c: 0xa0: eeprom for ccd defect map 90 i2c: 0xa0: eeprom for ccd defect map
91 */ 91 */
@@ -256,26 +256,26 @@ For the CCIR-601 standards, the sampling is based on a static orthogonal samplin
256//=========================================================================== 256//===========================================================================
257// Timing generator SRAM table values for CCIR601 720x480 NTSC 257// Timing generator SRAM table values for CCIR601 720x480 NTSC
258//=========================================================================== 258//===========================================================================
259// For NTSC CCIR656 259// For NTSC CCIR656
260BYTE BtCard::SRAMTable_NTSC[] = 260BYTE BtCard::SRAMTable_NTSC[] =
261{ 261{
262 // SRAM Timing Table for NTSC 262 // SRAM Timing Table for NTSC
263 0x0c, 0xc0, 0x00, 263 0x0c, 0xc0, 0x00,
264 0x00, 0x90, 0xc2, 264 0x00, 0x90, 0xc2,
265 0x03, 0x10, 0x03, 265 0x03, 0x10, 0x03,
266 0x06, 0x10, 0x34, 266 0x06, 0x10, 0x34,
267 0x12, 0x12, 0x65, 267 0x12, 0x12, 0x65,
268 0x02, 0x13, 0x24, 268 0x02, 0x13, 0x24,
269 0x19, 0x00, 0x24, 269 0x19, 0x00, 0x24,
270 0x39, 0x00, 0x96, 270 0x39, 0x00, 0x96,
271 0x59, 0x08, 0x93, 271 0x59, 0x08, 0x93,
272 0x83, 0x08, 0x97, 272 0x83, 0x08, 0x97,
273 0x03, 0x50, 0x30, 273 0x03, 0x50, 0x30,
274 0xc0, 0x40, 0x30, 274 0xc0, 0x40, 0x30,
275 0x86, 0x01, 0x01, 275 0x86, 0x01, 0x01,
276 0xa6, 0x0d, 0x62, 276 0xa6, 0x0d, 0x62,
277 0x03, 0x11, 0x61, 277 0x03, 0x11, 0x61,
278 0x05, 0x37, 0x30, 278 0x05, 0x37, 0x30,
279 0xac, 0x21, 0x50 279 0xac, 0x21, 0x50
280}; 280};
281 281
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index 72c7eb0f8c24..a5d529ccf3ad 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -288,22 +288,14 @@ bt856_command (struct i2c_client *client,
288 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 288 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
289 */ 289 */
290static unsigned short normal_i2c[] = { I2C_BT856 >> 1, I2C_CLIENT_END }; 290static unsigned short normal_i2c[] = { I2C_BT856 >> 1, I2C_CLIENT_END };
291static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
292 291
293static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 292static unsigned short ignore = I2C_CLIENT_END;
294static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
295static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
296static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
297static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
298 293
299static struct i2c_client_address_data addr_data = { 294static struct i2c_client_address_data addr_data = {
300 .normal_i2c = normal_i2c, 295 .normal_i2c = normal_i2c,
301 .normal_i2c_range = normal_i2c_range, 296 .probe = &ignore,
302 .probe = probe, 297 .ignore = &ignore,
303 .probe_range = probe_range, 298 .force = &ignore,
304 .ignore = ignore,
305 .ignore_range = ignore_range,
306 .force = force
307}; 299};
308 300
309static struct i2c_driver i2c_driver_bt856; 301static struct i2c_driver i2c_driver_bt856;
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index 85224b90e394..251092e7f19f 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-cards.c,v 1.47 2005/02/22 14:06:32 kraxel Exp $ 2 $Id: bttv-cards.c,v 1.49 2005/06/10 17:20:24 mchehab Exp $
3 3
4 bttv-cards.c 4 bttv-cards.c
5 5
@@ -51,6 +51,7 @@ static void avermedia_eeprom(struct bttv *btv);
51static void osprey_eeprom(struct bttv *btv); 51static void osprey_eeprom(struct bttv *btv);
52static void modtec_eeprom(struct bttv *btv); 52static void modtec_eeprom(struct bttv *btv);
53static void init_PXC200(struct bttv *btv); 53static void init_PXC200(struct bttv *btv);
54static void init_RTV24(struct bttv *btv);
54 55
55static void winview_audio(struct bttv *btv, struct video_audio *v, int set); 56static void winview_audio(struct bttv *btv, struct video_audio *v, int set);
56static void lt9415_audio(struct bttv *btv, struct video_audio *v, int set); 57static void lt9415_audio(struct bttv *btv, struct video_audio *v, int set);
@@ -1946,7 +1947,6 @@ struct tvcard bttv_tvcards[] = {
1946 .no_tda9875 = 1, 1947 .no_tda9875 = 1,
1947 .no_tda7432 = 1, 1948 .no_tda7432 = 1,
1948 .tuner_type = TUNER_ABSENT, 1949 .tuner_type = TUNER_ABSENT,
1949 .no_video = 1,
1950 .pll = PLL_28, 1950 .pll = PLL_28,
1951},{ 1951},{
1952 .name = "Teppro TEV-560/InterVision IV-560", 1952 .name = "Teppro TEV-560/InterVision IV-560",
@@ -2252,6 +2252,20 @@ struct tvcard bttv_tvcards[] = {
2252 .no_tda7432 = 1, 2252 .no_tda7432 = 1,
2253 .no_tda9875 = 1, 2253 .no_tda9875 = 1,
2254 .muxsel_hook = kodicom4400r_muxsel, 2254 .muxsel_hook = kodicom4400r_muxsel,
2255},
2256{
2257 /* ---- card 0x85---------------------------------- */
2258 /* Michael Henson <mhenson@clarityvi.com> */
2259 /* Adlink RTV24 with special unlock codes */
2260 .name = "Adlink RTV24",
2261 .video_inputs = 4,
2262 .audio_inputs = 1,
2263 .tuner = 0,
2264 .svhs = 2,
2265 .muxsel = { 2, 3, 1, 0},
2266 .tuner_type = -1,
2267 .pll = PLL_28,
2268
2255}}; 2269}};
2256 2270
2257static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards); 2271static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
@@ -2637,6 +2651,10 @@ void __devinit bttv_init_card1(struct bttv *btv)
2637 case BTTV_AVDVBT_771: 2651 case BTTV_AVDVBT_771:
2638 btv->use_i2c_hw = 1; 2652 btv->use_i2c_hw = 1;
2639 break; 2653 break;
2654 case BTTV_ADLINK_RTV24:
2655 init_RTV24( btv );
2656 break;
2657
2640 } 2658 }
2641 if (!bttv_tvcards[btv->c.type].has_dvb) 2659 if (!bttv_tvcards[btv->c.type].has_dvb)
2642 bttv_reset_audio(btv); 2660 bttv_reset_audio(btv);
@@ -2785,6 +2803,8 @@ void __devinit bttv_init_card2(struct bttv *btv)
2785 } 2803 }
2786 btv->pll.pll_current = -1; 2804 btv->pll.pll_current = -1;
2787 2805
2806 bttv_reset_audio(btv);
2807
2788 /* tuner configuration (from card list / autodetect / insmod option) */ 2808 /* tuner configuration (from card list / autodetect / insmod option) */
2789 if (UNSET != bttv_tvcards[btv->c.type].tuner_type) 2809 if (UNSET != bttv_tvcards[btv->c.type].tuner_type)
2790 if(UNSET == btv->tuner_type) 2810 if(UNSET == btv->tuner_type)
@@ -3305,6 +3325,83 @@ static void __devinit init_PXC200(struct bttv *btv)
3305} 3325}
3306 3326
3307 3327
3328
3329/* ----------------------------------------------------------------------- */
3330/*
3331 * The Adlink RTV-24 (aka Angelo) has some special initialisation to unlock
3332 * it. This apparently involves the following procedure for each 878 chip:
3333 *
3334 * 1) write 0x00C3FEFF to the GPIO_OUT_EN register
3335 *
3336 * 2) write to GPIO_DATA
3337 * - 0x0E
3338 * - sleep 1ms
3339 * - 0x10 + 0x0E
3340 * - sleep 10ms
3341 * - 0x0E
3342 * read from GPIO_DATA into buf (uint_32)
3343 * - if ( data>>18 & 0x01 != 0) || ( buf>>19 & 0x01 != 1 )
3344 * error. ERROR_CPLD_Check_Failed stop.
3345 *
3346 * 3) write to GPIO_DATA
3347 * - write 0x4400 + 0x0E
3348 * - sleep 10ms
3349 * - write 0x4410 + 0x0E
3350 * - sleep 1ms
3351 * - write 0x0E
3352 * read from GPIO_DATA into buf (uint_32)
3353 * - if ( buf>>18 & 0x01 ) || ( buf>>19 && 0x01 != 0 )
3354 * error. ERROR_CPLD_Check_Failed.
3355 */
3356/* ----------------------------------------------------------------------- */
3357void
3358init_RTV24 (struct bttv *btv)
3359{
3360 uint32_t dataRead = 0;
3361 long watchdog_value = 0x0E;
3362
3363 printk (KERN_INFO
3364 "bttv%d: Adlink RTV-24 initialisation in progress ...\n",
3365 btv->c.nr);
3366
3367 btwrite (0x00c3feff, BT848_GPIO_OUT_EN);
3368
3369 btwrite (0 + watchdog_value, BT848_GPIO_DATA);
3370 msleep (1);
3371 btwrite (0x10 + watchdog_value, BT848_GPIO_DATA);
3372 msleep (10);
3373 btwrite (0 + watchdog_value, BT848_GPIO_DATA);
3374
3375 dataRead = btread (BT848_GPIO_DATA);
3376
3377 if ((((dataRead >> 18) & 0x01) != 0) || (((dataRead >> 19) & 0x01) != 1)) {
3378 printk (KERN_INFO
3379 "bttv%d: Adlink RTV-24 initialisation(1) ERROR_CPLD_Check_Failed (read %d)\n",
3380 btv->c.nr, dataRead);
3381 }
3382
3383 btwrite (0x4400 + watchdog_value, BT848_GPIO_DATA);
3384 msleep (10);
3385 btwrite (0x4410 + watchdog_value, BT848_GPIO_DATA);
3386 msleep (1);
3387 btwrite (watchdog_value, BT848_GPIO_DATA);
3388 msleep (1);
3389 dataRead = btread (BT848_GPIO_DATA);
3390
3391 if ((((dataRead >> 18) & 0x01) != 0) || (((dataRead >> 19) & 0x01) != 0)) {
3392 printk (KERN_INFO
3393 "bttv%d: Adlink RTV-24 initialisation(2) ERROR_CPLD_Check_Failed (read %d)\n",
3394 btv->c.nr, dataRead);
3395
3396 return;
3397 }
3398
3399 printk (KERN_INFO
3400 "bttv%d: Adlink RTV-24 initialisation complete.\n", btv->c.nr);
3401}
3402
3403
3404
3308/* ----------------------------------------------------------------------- */ 3405/* ----------------------------------------------------------------------- */
3309/* Miro Pro radio stuff -- the tea5757 is connected to some GPIO ports */ 3406/* Miro Pro radio stuff -- the tea5757 is connected to some GPIO ports */
3310/* 3407/*
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 033cc5498f23..290289a99757 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-driver.c,v 1.37 2005/02/21 13:57:59 kraxel Exp $ 2 $Id: bttv-driver.c,v 1.38 2005/06/10 17:20:24 mchehab Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
diff --git a/drivers/media/video/bttv-i2c.c b/drivers/media/video/bttv-i2c.c
index e3f477dff827..da448a5f9e9c 100644
--- a/drivers/media/video/bttv-i2c.c
+++ b/drivers/media/video/bttv-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-i2c.c,v 1.18 2005/02/16 12:14:10 kraxel Exp $ 2 $Id: bttv-i2c.c,v 1.21 2005/06/10 17:20:24 mchehab Exp $
3 3
4 bttv-i2c.c -- all the i2c code is here 4 bttv-i2c.c -- all the i2c code is here
5 5
@@ -363,6 +363,9 @@ int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
363/* read EEPROM content */ 363/* read EEPROM content */
364void __devinit bttv_readee(struct bttv *btv, unsigned char *eedata, int addr) 364void __devinit bttv_readee(struct bttv *btv, unsigned char *eedata, int addr)
365{ 365{
366 memset(eedata, 0, 256);
367 if (0 != btv->i2c_rc)
368 return;
366 btv->i2c_client.addr = addr >> 1; 369 btv->i2c_client.addr = addr >> 1;
367 tveeprom_read(&btv->i2c_client, eedata, 256); 370 tveeprom_read(&btv->i2c_client, eedata, 256);
368} 371}
diff --git a/drivers/media/video/bttv.h b/drivers/media/video/bttv.h
index 8322b66e0905..191eaf1714ba 100644
--- a/drivers/media/video/bttv.h
+++ b/drivers/media/video/bttv.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: bttv.h,v 1.17 2005/02/22 14:06:32 kraxel Exp $ 2 * $Id: bttv.h,v 1.18 2005/05/24 23:41:42 nsh Exp $
3 * 3 *
4 * bttv - Bt848 frame grabber driver 4 * bttv - Bt848 frame grabber driver
5 * 5 *
@@ -135,6 +135,7 @@
135#define BTTV_DVICO_DVBT_LITE 0x80 135#define BTTV_DVICO_DVBT_LITE 0x80
136#define BTTV_TIBET_CS16 0x83 136#define BTTV_TIBET_CS16 0x83
137#define BTTV_KODICOM_4400R 0x84 137#define BTTV_KODICOM_4400R 0x84
138#define BTTV_ADLINK_RTV24 0x85
138 139
139/* i2c address list */ 140/* i2c address list */
140#define I2C_TSA5522 0xc2 141#define I2C_TSA5522 0xc2
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bttvp.h
index 1a9ba7e1cf51..7b6f1e856028 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bttvp.h
@@ -226,10 +226,6 @@ extern int fini_bttv_i2c(struct bttv *btv);
226#define dprintk if (bttv_debug >= 1) printk 226#define dprintk if (bttv_debug >= 1) printk
227#define d2printk if (bttv_debug >= 2) printk 227#define d2printk if (bttv_debug >= 2) printk
228 228
229/* our devices */
230#define BTTV_MAX 16
231extern unsigned int bttv_num;
232
233#define BTTV_MAX_FBUF 0x208000 229#define BTTV_MAX_FBUF 0x208000
234#define VBIBUF_SIZE (2048*VBI_MAXLINES*2) 230#define VBIBUF_SIZE (2048*VBI_MAXLINES*2)
235#define BTTV_TIMEOUT (HZ/2) /* 0.5 seconds */ 231#define BTTV_TIMEOUT (HZ/2) /* 0.5 seconds */
@@ -375,6 +371,10 @@ struct bttv {
375 unsigned int users; 371 unsigned int users;
376 struct bttv_fh init; 372 struct bttv_fh init;
377}; 373};
374
375/* our devices */
376#define BTTV_MAX 16
377extern unsigned int bttv_num;
378extern struct bttv bttvs[BTTV_MAX]; 378extern struct bttv bttvs[BTTV_MAX];
379 379
380/* private ioctls */ 380/* private ioctls */
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 46d6778b863b..91f8afeded88 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-blackbird.c,v 1.26 2005/03/07 15:58:05 kraxel Exp $ 2 * $Id: cx88-blackbird.c,v 1.27 2005/06/03 13:31:50 mchehab Exp $
3 * 3 *
4 * Support for a cx23416 mpeg encoder via cx2388x host port. 4 * Support for a cx23416 mpeg encoder via cx2388x host port.
5 * "blackbird" reference design. 5 * "blackbird" reference design.
@@ -61,37 +61,304 @@ static LIST_HEAD(cx8802_devlist);
61 61
62#define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF 62#define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF
63 63
64/*Firmware API commands*/ 64/* Firmware API commands */
65#define IVTV_API_ENC_PING_FW 0x00000080 65/* #define IVTV_API_STD_TIMEOUT 0x00010000 // 65536, units?? */
66#define IVTV_API_ENC_GETVER 0x000000C4 66#define IVTV_API_STD_TIMEOUT 500
67#define IVTV_API_ENC_HALT_FW 0x000000C3 67
68#define IVTV_API_STD_TIMEOUT 0x00010000 /*units??*/ 68#define BLACKBIRD_API_PING 0x80
69//#define IVTV_API_ASSIGN_PGM_INDEX_INFO 0x000000c7 69#define BLACKBIRD_API_BEGIN_CAPTURE 0x81
70#define IVTV_API_ASSIGN_STREAM_TYPE 0x000000b9 70enum blackbird_capture_type {
71#define IVTV_API_ASSIGN_OUTPUT_PORT 0x000000bb 71 BLACKBIRD_MPEG_CAPTURE,
72#define IVTV_API_ASSIGN_FRAMERATE 0x0000008f 72 BLACKBIRD_RAW_CAPTURE,
73#define IVTV_API_ASSIGN_FRAME_SIZE 0x00000091 73 BLACKBIRD_RAW_PASSTHRU_CAPTURE
74#define IVTV_API_ASSIGN_ASPECT_RATIO 0x00000099 74};
75#define IVTV_API_ASSIGN_BITRATES 0x00000095 75enum blackbird_capture_bits {
76#define IVTV_API_ASSIGN_GOP_PROPERTIES 0x00000097 76 BLACKBIRD_RAW_BITS_NONE = 0x00,
77#define IVTV_API_ASSIGN_3_2_PULLDOWN 0x000000b1 77 BLACKBIRD_RAW_BITS_YUV_CAPTURE = 0x01,
78#define IVTV_API_ASSIGN_GOP_CLOSURE 0x000000c5 78 BLACKBIRD_RAW_BITS_PCM_CAPTURE = 0x02,
79#define IVTV_API_ASSIGN_AUDIO_PROPERTIES 0x000000bd 79 BLACKBIRD_RAW_BITS_VBI_CAPTURE = 0x04,
80#define IVTV_API_ASSIGN_DNR_FILTER_MODE 0x0000009b 80 BLACKBIRD_RAW_BITS_PASSTHRU_CAPTURE = 0x08,
81#define IVTV_API_ASSIGN_DNR_FILTER_PROPS 0x0000009d 81 BLACKBIRD_RAW_BITS_TO_HOST_CAPTURE = 0x10
82#define IVTV_API_ASSIGN_CORING_LEVELS 0x0000009f 82};
83#define IVTV_API_ASSIGN_SPATIAL_FILTER_TYPE 0x000000a1 83#define BLACKBIRD_API_END_CAPTURE 0x82
84#define IVTV_API_ASSIGN_FRAME_DROP_RATE 0x000000d0 84enum blackbird_capture_end {
85#define IVTV_API_ASSIGN_PLACEHOLDER 0x000000d8 85 BLACKBIRD_END_AT_GOP, /* stop at the end of gop, generate irq */
86#define IVTV_API_MUTE_VIDEO 0x000000d9 86 BLACKBIRD_END_NOW, /* stop immediately, no irq */
87#define IVTV_API_MUTE_AUDIO 0x000000da 87};
88#define IVTV_API_INITIALIZE_INPUT 0x000000cd 88#define BLACKBIRD_API_SET_AUDIO_ID 0x89
89#define IVTV_API_REFRESH_INPUT 0x000000d3 89#define BLACKBIRD_API_SET_VIDEO_ID 0x8B
90#define IVTV_API_ASSIGN_NUM_VSYNC_LINES 0x000000d6 90#define BLACKBIRD_API_SET_PCR_ID 0x8D
91#define IVTV_API_BEGIN_CAPTURE 0x00000081 91#define BLACKBIRD_API_SET_FRAMERATE 0x8F
92//#define IVTV_API_PAUSE_ENCODER 0x000000d2 92enum blackbird_framerate {
93//#define IVTV_API_EVENT_NOTIFICATION 0x000000d5 93 BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */
94#define IVTV_API_END_CAPTURE 0x00000082 94 BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */
95};
96#define BLACKBIRD_API_SET_RESOLUTION 0x91
97#define BLACKBIRD_API_SET_VIDEO_BITRATE 0x95
98enum blackbird_video_bitrate_type {
99 BLACKBIRD_VIDEO_VBR,
100 BLACKBIRD_VIDEO_CBR
101};
102#define BLACKBIRD_PEAK_RATE_DIVISOR 400
103enum blackbird_mux_rate {
104 BLACKBIRD_MUX_RATE_DEFAULT,
105 /* dvd mux rate: multiply by 400 to get the actual rate */
106 BLACKBIRD_MUX_RATE_DVD = 25200
107};
108#define BLACKBIRD_API_SET_GOP_STRUCTURE 0x97
109#define BLACKBIRD_API_SET_ASPECT_RATIO 0x99
110enum blackbird_aspect_ratio {
111 BLACKBIRD_ASPECT_RATIO_FORBIDDEN,
112 BLACKBIRD_ASPECT_RATIO_1_1_SQUARE,
113 BLACKBIRD_ASPECT_RATIO_4_3,
114 BLACKBIRD_ASPECT_RATIO_16_9,
115 BLACKBIRD_ASPECT_RATIO_221_100,
116 BLACKBIRD_ASPECT_RATIO_RESERVED
117};
118#define BLACKBIRD_API_SET_DNR_MODE 0x9B
119enum blackbird_dnr_bits {
120 BLACKBIRD_DNR_BITS_MANUAL,
121 BLACKBIRD_DNR_BITS_AUTO_SPATIAL,
122 BLACKBIRD_DNR_BITS_AUTO_TEMPORAL,
123 BLACKBIRD_DNR_BITS_AUTO
124};
125enum blackbird_median_filter {
126 BLACKBIRD_MEDIAN_FILTER_DISABLED,
127 BLACKBIRD_MEDIAN_FILTER_HORIZONTAL,
128 BLACKBIRD_MEDIAN_FILTER_VERTICAL,
129 BLACKBIRD_MEDIAN_FILTER_HV,
130 BLACKBIRD_MEDIAN_FILTER_DIAGONAL
131};
132#define BLACKBIRD_API_SET_MANUAL_DNR 0x9D
133#define BLACKBIRD_API_SET_DNR_MEDIAN 0x9F
134#define BLACKBIRD_API_SET_SPATIAL_FILTER 0xA1
135enum blackbird_spatial_filter_luma {
136 BLACKBIRD_SPATIAL_FILTER_LUMA_DISABLED,
137 BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ,
138 BLACKBIRD_SPATIAL_FILTER_LUMA_1D_VERT,
139 BLACKBIRD_SPATIAL_FILTER_LUMA_2D_HV, /* separable, default */
140 BLACKBIRD_SPATIAL_FILTER_LUMA_2D_SYMM /* symmetric non-separable */
141};
142enum blackbird_spatial_filter_chroma {
143 BLACKBIRD_SPATIAL_FILTER_CHROMA_DISABLED,
144 BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ /* default */
145};
146#define BLACKBIRD_API_SET_3_2_PULLDOWN 0xB1
147enum blackbird_pulldown {
148 BLACKBIRD_3_2_PULLDOWN_DISABLED,
149 BLACKBIRD_3_2_PULLDOWN_ENABLED
150};
151#define BLACKBIRD_API_SET_VBI_LINE_NO 0xB7
152enum blackbird_vbi_line_bits {
153 BLACKBIRD_VBI_LINE_BITS_TOP_FIELD,
154 BLACKBIRD_VBI_LINE_BITS_BOT_FIELD = (1 << 31),
155 BLACKBIRD_VBI_LINE_BITS_ALL_LINES = 0xFFFFFFFF
156};
157enum blackbird_vbi_line {
158 BLACKBIRD_VBI_LINE_DISABLED,
159 BLACKBIRD_VBI_LINE_ENABLED
160};
161enum blackbird_vbi_slicing {
162 BLACKBIRD_VBI_SLICING_NONE,
163 BLACKBIRD_VBI_SLICING_CLOSED_CAPTION
164};
165#define BLACKBIRD_API_SET_STREAM_TYPE 0xB9
166enum blackbird_stream_type {
167 BLACKBIRD_STREAM_PROGRAM,
168 BLACKBIRD_STREAM_TRANSPORT,
169 BLACKBIRD_STREAM_MPEG1,
170 BLACKBIRD_STREAM_PES_AV,
171 BLACKBIRD_STREAM_UNKNOWN4,
172 BLACKBIRD_STREAM_PES_VIDEO,
173 BLACKBIRD_STREAM_UNKNOWN6,
174 BLACKBIRD_STREAM_PES_AUDIO,
175 BLACKBIRD_STREAM_UNKNOWN8,
176 BLACKBIRD_STREAM_UNKNOWN9, /* audio/pcm ? */
177 BLACKBIRD_STREAM_DVD,
178 BLACKBIRD_STREAM_VCD,
179 BLACKBIRD_STREAM_UNKNOWN12 /* svcd/xvcd ? */
180};
181#define BLACKBIRD_API_SET_OUTPUT_PORT 0xBB
182enum blackbird_stream_port {
183 BLACKBIRD_OUTPUT_PORT_MEMORY,
184 BLACKBIRD_OUTPUT_PORT_STREAMING,
185 BLACKBIRD_OUTPUT_PORT_SERIAL
186};
187#define BLACKBIRD_API_SET_AUDIO_PARAMS 0xBD
188enum blackbird_audio_bits_sample_rate {
189 BLACKBIRD_AUDIO_BITS_44100HZ,
190 BLACKBIRD_AUDIO_BITS_48000HZ,
191 BLACKBIRD_AUDIO_BITS_32000HZ,
192 BLACKBIRD_AUDIO_BITS_RESERVED_HZ,
193};
194enum blackbird_audio_bits_encoding {
195 BLACKBIRD_AUDIO_BITS_LAYER_1 = 0x1 << 2,
196 BLACKBIRD_AUDIO_BITS_LAYER_2 = 0x2 << 2,
197};
198enum blackbird_audio_bits_bitrate_layer_1 {
199 BLACKBIRD_AUDIO_BITS_LAYER_1_FREE_FORMAT,
200 BLACKBIRD_AUDIO_BITS_LAYER_1_32 = 0x01 << 4,
201 BLACKBIRD_AUDIO_BITS_LAYER_1_64 = 0x02 << 4,
202 BLACKBIRD_AUDIO_BITS_LAYER_1_96 = 0x03 << 4,
203 BLACKBIRD_AUDIO_BITS_LAYER_1_128 = 0x04 << 4,
204 BLACKBIRD_AUDIO_BITS_LAYER_1_160 = 0x05 << 4,
205 BLACKBIRD_AUDIO_BITS_LAYER_1_192 = 0x06 << 4,
206 BLACKBIRD_AUDIO_BITS_LAYER_1_224 = 0x07 << 4,
207 BLACKBIRD_AUDIO_BITS_LAYER_1_256 = 0x08 << 4,
208 BLACKBIRD_AUDIO_BITS_LAYER_1_288 = 0x09 << 4,
209 BLACKBIRD_AUDIO_BITS_LAYER_1_320 = 0x0A << 4,
210 BLACKBIRD_AUDIO_BITS_LAYER_1_352 = 0x0B << 4,
211 BLACKBIRD_AUDIO_BITS_LAYER_1_384 = 0x0C << 4,
212 BLACKBIRD_AUDIO_BITS_LAYER_1_416 = 0x0D << 4,
213 BLACKBIRD_AUDIO_BITS_LAYER_1_448 = 0x0E << 4,
214};
215enum blackbird_audio_bits_bitrate_layer_2 {
216 BLACKBIRD_AUDIO_BITS_LAYER_2_FREE_FORMAT,
217 BLACKBIRD_AUDIO_BITS_LAYER_2_32 = 0x01 << 4,
218 BLACKBIRD_AUDIO_BITS_LAYER_2_48 = 0x02 << 4,
219 BLACKBIRD_AUDIO_BITS_LAYER_2_56 = 0x03 << 4,
220 BLACKBIRD_AUDIO_BITS_LAYER_2_64 = 0x04 << 4,
221 BLACKBIRD_AUDIO_BITS_LAYER_2_80 = 0x05 << 4,
222 BLACKBIRD_AUDIO_BITS_LAYER_2_96 = 0x06 << 4,
223 BLACKBIRD_AUDIO_BITS_LAYER_2_112 = 0x07 << 4,
224 BLACKBIRD_AUDIO_BITS_LAYER_2_128 = 0x08 << 4,
225 BLACKBIRD_AUDIO_BITS_LAYER_2_160 = 0x09 << 4,
226 BLACKBIRD_AUDIO_BITS_LAYER_2_192 = 0x0A << 4,
227 BLACKBIRD_AUDIO_BITS_LAYER_2_224 = 0x0B << 4,
228 BLACKBIRD_AUDIO_BITS_LAYER_2_256 = 0x0C << 4,
229 BLACKBIRD_AUDIO_BITS_LAYER_2_320 = 0x0D << 4,
230 BLACKBIRD_AUDIO_BITS_LAYER_2_384 = 0x0E << 4,
231};
232enum blackbird_audio_bits_mode {
233 BLACKBIRD_AUDIO_BITS_STEREO,
234 BLACKBIRD_AUDIO_BITS_JOINT_STEREO = 0x1 << 8,
235 BLACKBIRD_AUDIO_BITS_DUAL = 0x2 << 8,
236 BLACKBIRD_AUDIO_BITS_MONO = 0x3 << 8,
237};
238enum blackbird_audio_bits_mode_extension {
239 BLACKBIRD_AUDIO_BITS_BOUND_4,
240 BLACKBIRD_AUDIO_BITS_BOUND_8 = 0x1 << 10,
241 BLACKBIRD_AUDIO_BITS_BOUND_12 = 0x2 << 10,
242 BLACKBIRD_AUDIO_BITS_BOUND_16 = 0x3 << 10,
243};
244enum blackbird_audio_bits_emphasis {
245 BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE,
246 BLACKBIRD_AUDIO_BITS_EMPHASIS_50_15 = 0x1 << 12,
247 BLACKBIRD_AUDIO_BITS_EMPHASIS_RESERVED = 0x2 << 12,
248 BLACKBIRD_AUDIO_BITS_EMPHASIS_CCITT_J17 = 0x3 << 12,
249};
250enum blackbird_audio_bits_crc {
251 BLACKBIRD_AUDIO_BITS_CRC_OFF,
252 BLACKBIRD_AUDIO_BITS_CRC_ON = 0x1 << 14,
253};
254enum blackbird_audio_bits_copyright {
255 BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF,
256 BLACKBIRD_AUDIO_BITS_COPYRIGHT_ON = 0x1 << 15,
257};
258enum blackbird_audio_bits_original {
259 BLACKBIRD_AUDIO_BITS_COPY,
260 BLACKBIRD_AUDIO_BITS_ORIGINAL = 0x1 << 16,
261};
262#define BLACKBIRD_API_HALT 0xC3
263#define BLACKBIRD_API_GET_VERSION 0xC4
264#define BLACKBIRD_API_SET_GOP_CLOSURE 0xC5
265enum blackbird_gop_closure {
266 BLACKBIRD_GOP_CLOSURE_OFF,
267 BLACKBIRD_GOP_CLOSURE_ON,
268};
269#define BLACKBIRD_API_DATA_XFER_STATUS 0xC6
270enum blackbird_data_xfer_status {
271 BLACKBIRD_MORE_BUFFERS_FOLLOW,
272 BLACKBIRD_LAST_BUFFER,
273};
274#define BLACKBIRD_API_PROGRAM_INDEX_INFO 0xC7
275enum blackbird_picture_mask {
276 BLACKBIRD_PICTURE_MASK_NONE,
277 BLACKBIRD_PICTURE_MASK_I_FRAMES,
278 BLACKBIRD_PICTURE_MASK_I_P_FRAMES = 0x3,
279 BLACKBIRD_PICTURE_MASK_ALL_FRAMES = 0x7,
280};
281#define BLACKBIRD_API_SET_VBI_PARAMS 0xC8
282enum blackbird_vbi_mode_bits {
283 BLACKBIRD_VBI_BITS_SLICED,
284 BLACKBIRD_VBI_BITS_RAW,
285};
286enum blackbird_vbi_insertion_bits {
287 BLACKBIRD_VBI_BITS_INSERT_IN_XTENSION_USR_DATA,
288 BLACKBIRD_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1,
289 BLACKBIRD_VBI_BITS_SEPARATE_STREAM = 0x2 << 1,
290 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1,
291 BLACKBIRD_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1,
292};
293#define BLACKBIRD_API_SET_DMA_BLOCK_SIZE 0xC9
294enum blackbird_dma_unit {
295 BLACKBIRD_DMA_BYTES,
296 BLACKBIRD_DMA_FRAMES,
297};
298#define BLACKBIRD_API_DMA_TRANSFER_INFO 0xCA
299#define BLACKBIRD_API_DMA_TRANSFER_STAT 0xCB
300enum blackbird_dma_transfer_status_bits {
301 BLACKBIRD_DMA_TRANSFER_BITS_DONE = 0x01,
302 BLACKBIRD_DMA_TRANSFER_BITS_ERROR = 0x04,
303 BLACKBIRD_DMA_TRANSFER_BITS_LL_ERROR = 0x10,
304};
305#define BLACKBIRD_API_SET_DMA2HOST_ADDR 0xCC
306#define BLACKBIRD_API_INIT_VIDEO_INPUT 0xCD
307#define BLACKBIRD_API_SET_FRAMESKIP 0xD0
308#define BLACKBIRD_API_PAUSE 0xD2
309enum blackbird_pause {
310 BLACKBIRD_PAUSE_ENCODING,
311 BLACKBIRD_RESUME_ENCODING,
312};
313#define BLACKBIRD_API_REFRESH_INPUT 0xD3
314#define BLACKBIRD_API_SET_COPYRIGHT 0xD4
315enum blackbird_copyright {
316 BLACKBIRD_COPYRIGHT_OFF,
317 BLACKBIRD_COPYRIGHT_ON,
318};
319#define BLACKBIRD_API_SET_NOTIFICATION 0xD5
320enum blackbird_notification_type {
321 BLACKBIRD_NOTIFICATION_REFRESH,
322};
323enum blackbird_notification_status {
324 BLACKBIRD_NOTIFICATION_OFF,
325 BLACKBIRD_NOTIFICATION_ON,
326};
327enum blackbird_notification_mailbox {
328 BLACKBIRD_NOTIFICATION_NO_MAILBOX = -1,
329};
330#define BLACKBIRD_API_SET_CAPTURE_LINES 0xD6
331enum blackbird_field1_lines {
332 BLACKBIRD_FIELD1_SAA7114 = 0x00EF, /* 239 */
333 BLACKBIRD_FIELD1_SAA7115 = 0x00F0, /* 240 */
334 BLACKBIRD_FIELD1_MICRONAS = 0x0105, /* 261 */
335};
336enum blackbird_field2_lines {
337 BLACKBIRD_FIELD2_SAA7114 = 0x00EF, /* 239 */
338 BLACKBIRD_FIELD2_SAA7115 = 0x00F0, /* 240 */
339 BLACKBIRD_FIELD2_MICRONAS = 0x0106, /* 262 */
340};
341#define BLACKBIRD_API_SET_CUSTOM_DATA 0xD7
342enum blackbird_custom_data_type {
343 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
344 BLACKBIRD_CUSTOM_PRIVATE_PACKET,
345};
346#define BLACKBIRD_API_MUTE_VIDEO 0xD9
347enum blackbird_mute {
348 BLACKBIRD_UNMUTE,
349 BLACKBIRD_MUTE,
350};
351enum blackbird_mute_video_mask {
352 BLACKBIRD_MUTE_VIDEO_V_MASK = 0x0000FF00,
353 BLACKBIRD_MUTE_VIDEO_U_MASK = 0x00FF0000,
354 BLACKBIRD_MUTE_VIDEO_Y_MASK = 0xFF000000,
355};
356enum blackbird_mute_video_shift {
357 BLACKBIRD_MUTE_VIDEO_V_SHIFT = 8,
358 BLACKBIRD_MUTE_VIDEO_U_SHIFT = 16,
359 BLACKBIRD_MUTE_VIDEO_Y_SHIFT = 24,
360};
361#define BLACKBIRD_API_MUTE_AUDIO 0xDA
95 362
96/* Registers */ 363/* Registers */
97#define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8 /*| IVTV_REG_OFFSET*/) 364#define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8 /*| IVTV_REG_OFFSET*/)
@@ -405,68 +672,100 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
405 return 0; 672 return 0;
406} 673}
407 674
675/**
676 Settings used by the windows tv app for PVR2000:
677=================================================================================================================
678Profile | Codec | Resolution | CBR/VBR | Video Qlty | V. Bitrate | Frmrate | Audio Codec | A. Bitrate | A. Mode
679-----------------------------------------------------------------------------------------------------------------
680MPEG-1 | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 2000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
681MPEG-2 | MPEG2 | 720x576PAL | VBR | 600 :Good | 4000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
682VCD | MPEG1 | 352x288PAL | (CBR) | 1000:Optimal | 1150 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
683DVD | MPEG2 | 720x576PAL | VBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
684DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | MPG1 Layer2 | 224kbps | Stereo
685=================================================================================================================
686*DB: "DirectBurn"
687*/
408static void blackbird_codec_settings(struct cx8802_dev *dev) 688static void blackbird_codec_settings(struct cx8802_dev *dev)
409{ 689{
410 int bitrate_mode = 1; 690 int bitrate_mode = 1;
411 int bitrate = 7500000; 691 int bitrate = 7500000;
412 int bitrate_peak = 7500000; 692 int bitrate_peak = 7500000;
693#if 1
694 bitrate_mode = BLACKBIRD_VIDEO_CBR;
695 bitrate = 4000*1024;
696 bitrate_peak = 4000*1024;
697#endif
413 698
414 /* assign stream type */ 699 /* assign stream type */
415 blackbird_api_cmd(dev, IVTV_API_ASSIGN_STREAM_TYPE, 1, 0, 0); /* program stream */ 700 blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_PROGRAM);
416 //blackbird_api_cmd(dev, IVTV_API_ASSIGN_STREAM_TYPE, 1, 0, 2); /* MPEG1 stream */ 701 /* blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_TRANSPORT); */
417 //blackbird_api_cmd(dev, IVTV_API_ASSIGN_STREAM_TYPE, 1, 0, 3); /* PES A/V */
418 //blackbird_api_cmd(dev, IVTV_API_ASSIGN_STREAM_TYPE, 1, 0, 10); /* DVD stream */
419 702
420 /* assign output port */ 703 /* assign output port */
421 blackbird_api_cmd(dev, IVTV_API_ASSIGN_OUTPUT_PORT, 1, 0, 1); /* 1 = Host */ 704 blackbird_api_cmd(dev, BLACKBIRD_API_SET_OUTPUT_PORT, 1, 0, BLACKBIRD_OUTPUT_PORT_STREAMING); /* Host */
422 705
423 /* assign framerate */ 706 /* assign framerate */
424 blackbird_api_cmd(dev, IVTV_API_ASSIGN_FRAMERATE, 1, 0, 0); 707 blackbird_api_cmd(dev, BLACKBIRD_API_SET_FRAMERATE, 1, 0, BLACKBIRD_FRAMERATE_PAL_25);
425 708
426 /* assign frame size */ 709 /* assign frame size */
427 blackbird_api_cmd(dev, IVTV_API_ASSIGN_FRAME_SIZE, 2, 0, 710 blackbird_api_cmd(dev, BLACKBIRD_API_SET_RESOLUTION, 2, 0,
428 dev->height, dev->width); 711 dev->height, dev->width);
429 712
430 /* assign aspect ratio */ 713 /* assign aspect ratio */
431 blackbird_api_cmd(dev, IVTV_API_ASSIGN_ASPECT_RATIO, 1, 0, 2); 714 blackbird_api_cmd(dev, BLACKBIRD_API_SET_ASPECT_RATIO, 1, 0, BLACKBIRD_ASPECT_RATIO_4_3);
432 715
433 /* assign bitrates */ 716 /* assign bitrates */
434 blackbird_api_cmd(dev, IVTV_API_ASSIGN_BITRATES, 5, 0, 717 blackbird_api_cmd(dev, BLACKBIRD_API_SET_VIDEO_BITRATE, 5, 0,
435 bitrate_mode, /* mode */ 718 bitrate_mode, /* mode */
436 bitrate, /* bps */ 719 bitrate, /* bps */
437 bitrate_peak / 400, /* peak/400 */ 720 bitrate_peak / BLACKBIRD_PEAK_RATE_DIVISOR, /* peak/400 */
438 0, 0x70); /* encoding buffer, ckennedy */ 721 BLACKBIRD_MUX_RATE_DEFAULT /*, 0x70*/); /* encoding buffer, ckennedy */
439 722
440 /* assign gop properties */ 723 /* assign gop properties */
441 blackbird_api_cmd(dev, IVTV_API_ASSIGN_GOP_PROPERTIES, 2, 0, 15, 3); 724 blackbird_api_cmd(dev, BLACKBIRD_API_SET_GOP_STRUCTURE, 2, 0, 15, 3);
442 //blackbird_api_cmd(dev, IVTV_API_ASSIGN_GOP_PROPERTIES, 2, 0, 2, 1); 725
443 726 /* assign 3 2 pulldown */
444 /* assign 3 2 pulldown */ 727 blackbird_api_cmd(dev, BLACKBIRD_API_SET_3_2_PULLDOWN, 1, 0, BLACKBIRD_3_2_PULLDOWN_DISABLED);
445 blackbird_api_cmd(dev, IVTV_API_ASSIGN_3_2_PULLDOWN, 1, 0, 0); 728
446 729 /* assign audio properties */
447 /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */ 730 /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */
448 blackbird_api_cmd(dev, IVTV_API_ASSIGN_AUDIO_PROPERTIES, 1, 0, (2<<2) | (8<<4)); 731 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_AUDIO_PROPERTIES, 1, 0, (2<<2) | (8<<4));
732 blackbird_api_cmd(dev, IVTV_API_ASSIGN_AUDIO_PROPERTIES, 1, 0, 0 | (2 << 2) | (14 << 4)); */
733 blackbird_api_cmd(dev, BLACKBIRD_API_SET_AUDIO_PARAMS, 1, 0,
734 BLACKBIRD_AUDIO_BITS_44100HZ |
735 BLACKBIRD_AUDIO_BITS_LAYER_2 |
736 BLACKBIRD_AUDIO_BITS_LAYER_2_224 |
737 BLACKBIRD_AUDIO_BITS_STEREO |
738 /* BLACKBIRD_AUDIO_BITS_BOUND_4 | */
739 BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE |
740 BLACKBIRD_AUDIO_BITS_CRC_OFF |
741 BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF |
742 BLACKBIRD_AUDIO_BITS_COPY
743 );
449 744
450 /* assign gop closure */ 745 /* assign gop closure */
451 blackbird_api_cmd(dev, IVTV_API_ASSIGN_GOP_CLOSURE, 1, 0, 0); 746 blackbird_api_cmd(dev, BLACKBIRD_API_SET_GOP_CLOSURE, 1, 0, BLACKBIRD_GOP_CLOSURE_OFF);
452 747
453 /* assign audio properties */
454 blackbird_api_cmd(dev, IVTV_API_ASSIGN_AUDIO_PROPERTIES, 1, 0, 0 | (2 << 2) | (14 << 4));
455 748
456 /* assign dnr filter mode */ 749 /* assign dnr filter mode */
457 blackbird_api_cmd(dev, IVTV_API_ASSIGN_DNR_FILTER_MODE, 2, 0, 0, 0); 750 blackbird_api_cmd(dev, BLACKBIRD_API_SET_DNR_MODE, 2, 0,
751 BLACKBIRD_DNR_BITS_MANUAL,
752 BLACKBIRD_MEDIAN_FILTER_DISABLED
753 );
458 754
459 /* assign dnr filter props*/ 755 /* assign dnr filter props*/
460 blackbird_api_cmd(dev, IVTV_API_ASSIGN_DNR_FILTER_PROPS, 2, 0, 0, 0); 756 blackbird_api_cmd(dev, BLACKBIRD_API_SET_MANUAL_DNR, 2, 0, 0, 0);
461 757
462 /* assign coring levels (luma_h, luma_l, chroma_h, chroma_l) */ 758 /* assign coring levels (luma_h, luma_l, chroma_h, chroma_l) */
463 blackbird_api_cmd(dev, IVTV_API_ASSIGN_CORING_LEVELS, 4, 0, 0, 255, 0, 255); 759 blackbird_api_cmd(dev, BLACKBIRD_API_SET_DNR_MEDIAN, 4, 0, 0, 255, 0, 255);
464 760
465 /* assign spatial filter type: luma_t: 1 = horiz_only, chroma_t: 1 = horiz_only */ 761 /* assign spatial filter type: luma_t: horiz_only, chroma_t: horiz_only */
466 blackbird_api_cmd(dev, IVTV_API_ASSIGN_SPATIAL_FILTER_TYPE, 2, 0, 1, 1); 762 blackbird_api_cmd(dev, BLACKBIRD_API_SET_SPATIAL_FILTER, 2, 0,
763 BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ,
764 BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ
765 );
467 766
468 /* assign frame drop rate */ 767 /* assign frame drop rate */
469 blackbird_api_cmd(dev, IVTV_API_ASSIGN_FRAME_DROP_RATE, 1, 0, 0); 768 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_FRAME_DROP_RATE, 1, 0, 0); */
470} 769}
471 770
472static int blackbird_initialize_codec(struct cx8802_dev *dev) 771static int blackbird_initialize_codec(struct cx8802_dev *dev)
@@ -476,7 +775,7 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
476 int retval; 775 int retval;
477 776
478 dprintk(1,"Initialize codec\n"); 777 dprintk(1,"Initialize codec\n");
479 retval = blackbird_api_cmd(dev, IVTV_API_ENC_PING_FW, 0, 0); /* ping */ 778 retval = blackbird_api_cmd(dev, BLACKBIRD_API_PING, 0, 0); /* ping */
480 if (retval < 0) { 779 if (retval < 0) {
481 /* ping was not successful, reset and upload firmware */ 780 /* ping was not successful, reset and upload firmware */
482 cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */ 781 cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */
@@ -491,13 +790,13 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
491 if (dev->mailbox < 0) 790 if (dev->mailbox < 0)
492 return -1; 791 return -1;
493 792
494 retval = blackbird_api_cmd(dev, IVTV_API_ENC_PING_FW, 0, 0); /* ping */ 793 retval = blackbird_api_cmd(dev, BLACKBIRD_API_PING, 0, 0); /* ping */
495 if (retval < 0) { 794 if (retval < 0) {
496 dprintk(0, "ERROR: Firmware ping failed!\n"); 795 dprintk(0, "ERROR: Firmware ping failed!\n");
497 return -1; 796 return -1;
498 } 797 }
499 798
500 retval = blackbird_api_cmd(dev, IVTV_API_ENC_GETVER, 0, 1, &version); 799 retval = blackbird_api_cmd(dev, BLACKBIRD_API_GET_VERSION, 0, 1, &version);
501 if (retval < 0) { 800 if (retval < 0) {
502 dprintk(0, "ERROR: Firmware get encoder version failed!\n"); 801 dprintk(0, "ERROR: Firmware get encoder version failed!\n");
503 return -1; 802 return -1;
@@ -517,25 +816,36 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
517 blackbird_codec_settings(dev); 816 blackbird_codec_settings(dev);
518 msleep(1); 817 msleep(1);
519 818
520 //blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xef, 0xef); 819 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xef, 0xef);
521 blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xf0, 0xf0); 820 blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0xf0, 0xf0);
522 //blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0x180, 0x180); 821 blackbird_api_cmd(dev, IVTV_API_ASSIGN_NUM_VSYNC_LINES, 4, 0, 0x180, 0x180); */
523 blackbird_api_cmd(dev, IVTV_API_ASSIGN_PLACEHOLDER, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 822 blackbird_api_cmd(dev, BLACKBIRD_API_SET_CAPTURE_LINES, 2, 0,
823 BLACKBIRD_FIELD1_SAA7115,
824 BLACKBIRD_FIELD1_SAA7115
825 );
826
827 /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_PLACEHOLDER, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); */
828 blackbird_api_cmd(dev, BLACKBIRD_API_SET_CUSTOM_DATA, 12, 0,
829 BLACKBIRD_CUSTOM_EXTENSION_USR_DATA,
830 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
524 831
525 blackbird_api_cmd(dev, IVTV_API_INITIALIZE_INPUT, 0, 0); /* initialize the video input */ 832 blackbird_api_cmd(dev, BLACKBIRD_API_INIT_VIDEO_INPUT, 0, 0); /* initialize the video input */
526 833
527 msleep(1); 834 msleep(1);
528 835
529 blackbird_api_cmd(dev, IVTV_API_MUTE_VIDEO, 1, 0, 0); 836 blackbird_api_cmd(dev, BLACKBIRD_API_MUTE_VIDEO, 1, 0, BLACKBIRD_UNMUTE);
530 msleep(1); 837 msleep(1);
531 blackbird_api_cmd(dev, IVTV_API_MUTE_AUDIO, 1, 0, 0); 838 blackbird_api_cmd(dev, BLACKBIRD_API_MUTE_AUDIO, 1, 0, BLACKBIRD_UNMUTE);
532 msleep(1); 839 msleep(1);
533 840
534 blackbird_api_cmd(dev, IVTV_API_BEGIN_CAPTURE, 2, 0, 0, 0x13); /* start capturing to the host interface */ 841 /* blackbird_api_cmd(dev, BLACKBIRD_API_BEGIN_CAPTURE, 2, 0, 0, 0x13); // start capturing to the host interface */
535 //blackbird_api_cmd(dev, IVTV_API_BEGIN_CAPTURE, 2, 0, 0, 0); /* start capturing to the host interface */ 842 blackbird_api_cmd(dev, BLACKBIRD_API_BEGIN_CAPTURE, 2, 0,
536 msleep(1); 843 BLACKBIRD_MPEG_CAPTURE,
844 BLACKBIRD_RAW_BITS_NONE
845 ); /* start capturing to the host interface */
846 msleep(10);
537 847
538 blackbird_api_cmd(dev, IVTV_API_REFRESH_INPUT, 0,0); 848 blackbird_api_cmd(dev, BLACKBIRD_API_REFRESH_INPUT, 0,0);
539 return 0; 849 return 0;
540} 850}
541 851
@@ -709,7 +1019,12 @@ static int mpeg_release(struct inode *inode, struct file *file)
709{ 1019{
710 struct cx8802_fh *fh = file->private_data; 1020 struct cx8802_fh *fh = file->private_data;
711 1021
712 blackbird_api_cmd(fh->dev, IVTV_API_END_CAPTURE, 3, 0, 1, 0, 0x13); 1022 /* blackbird_api_cmd(fh->dev, BLACKBIRD_API_END_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */
1023 blackbird_api_cmd(fh->dev, BLACKBIRD_API_END_CAPTURE, 3, 0,
1024 BLACKBIRD_END_NOW,
1025 BLACKBIRD_MPEG_CAPTURE,
1026 BLACKBIRD_RAW_BITS_NONE
1027 );
713 1028
714 /* stop mpeg capture */ 1029 /* stop mpeg capture */
715 if (fh->mpegq.streaming) 1030 if (fh->mpegq.streaming)
@@ -908,4 +1223,5 @@ module_exit(blackbird_fini);
908 * Local variables: 1223 * Local variables:
909 * c-basic-offset: 8 1224 * c-basic-offset: 8
910 * End: 1225 * End:
1226 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
911 */ 1227 */
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 367624822d77..b3fb04356b71 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-cards.c,v 1.66 2005/03/04 09:12:23 kraxel Exp $ 2 * $Id: cx88-cards.c,v 1.76 2005/06/08 01:28:09 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * card-specific stuff. 5 * card-specific stuff.
@@ -35,6 +35,9 @@ struct cx88_board cx88_boards[] = {
35 [CX88_BOARD_UNKNOWN] = { 35 [CX88_BOARD_UNKNOWN] = {
36 .name = "UNKNOWN/GENERIC", 36 .name = "UNKNOWN/GENERIC",
37 .tuner_type = UNSET, 37 .tuner_type = UNSET,
38 .radio_type = UNSET,
39 .tuner_addr = ADDR_UNSET,
40 .radio_addr = ADDR_UNSET,
38 .input = {{ 41 .input = {{
39 .type = CX88_VMUX_COMPOSITE1, 42 .type = CX88_VMUX_COMPOSITE1,
40 .vmux = 0, 43 .vmux = 0,
@@ -52,6 +55,9 @@ struct cx88_board cx88_boards[] = {
52 [CX88_BOARD_HAUPPAUGE] = { 55 [CX88_BOARD_HAUPPAUGE] = {
53 .name = "Hauppauge WinTV 34xxx models", 56 .name = "Hauppauge WinTV 34xxx models",
54 .tuner_type = UNSET, 57 .tuner_type = UNSET,
58 .radio_type = UNSET,
59 .tuner_addr = ADDR_UNSET,
60 .radio_addr = ADDR_UNSET,
55 .tda9887_conf = TDA9887_PRESENT, 61 .tda9887_conf = TDA9887_PRESENT,
56 .input = {{ 62 .input = {{
57 .type = CX88_VMUX_TELEVISION, 63 .type = CX88_VMUX_TELEVISION,
@@ -78,6 +84,9 @@ struct cx88_board cx88_boards[] = {
78 [CX88_BOARD_GDI] = { 84 [CX88_BOARD_GDI] = {
79 .name = "GDI Black Gold", 85 .name = "GDI Black Gold",
80 .tuner_type = UNSET, 86 .tuner_type = UNSET,
87 .radio_type = UNSET,
88 .tuner_addr = ADDR_UNSET,
89 .radio_addr = ADDR_UNSET,
81 .input = {{ 90 .input = {{
82 .type = CX88_VMUX_TELEVISION, 91 .type = CX88_VMUX_TELEVISION,
83 .vmux = 0, 92 .vmux = 0,
@@ -85,7 +94,10 @@ struct cx88_board cx88_boards[] = {
85 }, 94 },
86 [CX88_BOARD_PIXELVIEW] = { 95 [CX88_BOARD_PIXELVIEW] = {
87 .name = "PixelView", 96 .name = "PixelView",
88 .tuner_type = 5, 97 .tuner_type = TUNER_PHILIPS_PAL,
98 .radio_type = UNSET,
99 .tuner_addr = ADDR_UNSET,
100 .radio_addr = ADDR_UNSET,
89 .input = {{ 101 .input = {{
90 .type = CX88_VMUX_TELEVISION, 102 .type = CX88_VMUX_TELEVISION,
91 .vmux = 0, 103 .vmux = 0,
@@ -104,7 +116,10 @@ struct cx88_board cx88_boards[] = {
104 }, 116 },
105 [CX88_BOARD_ATI_WONDER_PRO] = { 117 [CX88_BOARD_ATI_WONDER_PRO] = {
106 .name = "ATI TV Wonder Pro", 118 .name = "ATI TV Wonder Pro",
107 .tuner_type = 44, 119 .tuner_type = TUNER_PHILIPS_4IN1,
120 .radio_type = UNSET,
121 .tuner_addr = ADDR_UNSET,
122 .radio_addr = ADDR_UNSET,
108 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER, 123 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER,
109 .input = {{ 124 .input = {{
110 .type = CX88_VMUX_TELEVISION, 125 .type = CX88_VMUX_TELEVISION,
@@ -122,7 +137,10 @@ struct cx88_board cx88_boards[] = {
122 }, 137 },
123 [CX88_BOARD_WINFAST2000XP_EXPERT] = { 138 [CX88_BOARD_WINFAST2000XP_EXPERT] = {
124 .name = "Leadtek Winfast 2000XP Expert", 139 .name = "Leadtek Winfast 2000XP Expert",
125 .tuner_type = 44, 140 .tuner_type = TUNER_PHILIPS_4IN1,
141 .radio_type = UNSET,
142 .tuner_addr = ADDR_UNSET,
143 .radio_addr = ADDR_UNSET,
126 .tda9887_conf = TDA9887_PRESENT, 144 .tda9887_conf = TDA9887_PRESENT,
127 .input = {{ 145 .input = {{
128 .type = CX88_VMUX_TELEVISION, 146 .type = CX88_VMUX_TELEVISION,
@@ -156,7 +174,10 @@ struct cx88_board cx88_boards[] = {
156 }, 174 },
157 [CX88_BOARD_AVERTV_303] = { 175 [CX88_BOARD_AVERTV_303] = {
158 .name = "AverTV Studio 303 (M126)", 176 .name = "AverTV Studio 303 (M126)",
159 .tuner_type = 38, 177 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
178 .radio_type = UNSET,
179 .tuner_addr = ADDR_UNSET,
180 .radio_addr = ADDR_UNSET,
160 .tda9887_conf = TDA9887_PRESENT, 181 .tda9887_conf = TDA9887_PRESENT,
161 .input = {{ 182 .input = {{
162 .type = CX88_VMUX_TELEVISION, 183 .type = CX88_VMUX_TELEVISION,
@@ -179,7 +200,10 @@ struct cx88_board cx88_boards[] = {
179 // added gpio values thanks to Michal 200 // added gpio values thanks to Michal
180 // values for PAL from DScaler 201 // values for PAL from DScaler
181 .name = "MSI TV-@nywhere Master", 202 .name = "MSI TV-@nywhere Master",
182 .tuner_type = 33, 203 .tuner_type = TUNER_MT2032,
204 .radio_type = UNSET,
205 .tuner_addr = ADDR_UNSET,
206 .radio_addr = ADDR_UNSET,
183 .tda9887_conf = TDA9887_PRESENT, 207 .tda9887_conf = TDA9887_PRESENT,
184 .input = {{ 208 .input = {{
185 .type = CX88_VMUX_TELEVISION, 209 .type = CX88_VMUX_TELEVISION,
@@ -206,7 +230,10 @@ struct cx88_board cx88_boards[] = {
206 }, 230 },
207 [CX88_BOARD_WINFAST_DV2000] = { 231 [CX88_BOARD_WINFAST_DV2000] = {
208 .name = "Leadtek Winfast DV2000", 232 .name = "Leadtek Winfast DV2000",
209 .tuner_type = 38, 233 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
234 .radio_type = UNSET,
235 .tuner_addr = ADDR_UNSET,
236 .radio_addr = ADDR_UNSET,
210 .tda9887_conf = TDA9887_PRESENT, 237 .tda9887_conf = TDA9887_PRESENT,
211 .input = {{ 238 .input = {{
212 .type = CX88_VMUX_TELEVISION, 239 .type = CX88_VMUX_TELEVISION,
@@ -239,34 +266,40 @@ struct cx88_board cx88_boards[] = {
239 .gpio3 = 0x02000000, 266 .gpio3 = 0x02000000,
240 }, 267 },
241 }, 268 },
242 [CX88_BOARD_LEADTEK_PVR2000] = { 269 [CX88_BOARD_LEADTEK_PVR2000] = {
243 // gpio values for PAL version from regspy by DScaler 270 // gpio values for PAL version from regspy by DScaler
244 .name = "Leadtek PVR 2000", 271 .name = "Leadtek PVR 2000",
245 .tuner_type = 38, 272 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
273 .radio_type = UNSET,
274 .tuner_addr = ADDR_UNSET,
275 .radio_addr = ADDR_UNSET,
246 .tda9887_conf = TDA9887_PRESENT, 276 .tda9887_conf = TDA9887_PRESENT,
247 .input = {{ 277 .input = {{
248 .type = CX88_VMUX_TELEVISION, 278 .type = CX88_VMUX_TELEVISION,
249 .vmux = 0, 279 .vmux = 0,
250 .gpio0 = 0x0000bde6, 280 .gpio0 = 0x0000bde2,
251 },{ 281 },{
252 .type = CX88_VMUX_COMPOSITE1, 282 .type = CX88_VMUX_COMPOSITE1,
253 .vmux = 1, 283 .vmux = 1,
254 .gpio0 = 0x0000bde6, 284 .gpio0 = 0x0000bde6,
255 },{ 285 },{
256 .type = CX88_VMUX_SVIDEO, 286 .type = CX88_VMUX_SVIDEO,
257 .vmux = 2, 287 .vmux = 2,
258 .gpio0 = 0x0000bde6, 288 .gpio0 = 0x0000bde6,
259 }}, 289 }},
260 .radio = { 290 .radio = {
261 .type = CX88_RADIO, 291 .type = CX88_RADIO,
262 .gpio0 = 0x0000bd62, 292 .gpio0 = 0x0000bd62,
263 }, 293 },
264 .blackbird = 1, 294 .blackbird = 1,
265 }, 295 },
266 [CX88_BOARD_IODATA_GVVCP3PCI] = { 296 [CX88_BOARD_IODATA_GVVCP3PCI] = {
267 .name = "IODATA GV-VCP3/PCI", 297 .name = "IODATA GV-VCP3/PCI",
268 .tuner_type = TUNER_ABSENT, 298 .tuner_type = TUNER_ABSENT,
269 .input = {{ 299 .radio_type = UNSET,
300 .tuner_addr = ADDR_UNSET,
301 .radio_addr = ADDR_UNSET,
302 .input = {{
270 .type = CX88_VMUX_COMPOSITE1, 303 .type = CX88_VMUX_COMPOSITE1,
271 .vmux = 0, 304 .vmux = 0,
272 },{ 305 },{
@@ -279,7 +312,10 @@ struct cx88_board cx88_boards[] = {
279 }, 312 },
280 [CX88_BOARD_PROLINK_PLAYTVPVR] = { 313 [CX88_BOARD_PROLINK_PLAYTVPVR] = {
281 .name = "Prolink PlayTV PVR", 314 .name = "Prolink PlayTV PVR",
282 .tuner_type = 43, 315 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
316 .radio_type = UNSET,
317 .tuner_addr = ADDR_UNSET,
318 .radio_addr = ADDR_UNSET,
283 .tda9887_conf = TDA9887_PRESENT, 319 .tda9887_conf = TDA9887_PRESENT,
284 .input = {{ 320 .input = {{
285 .type = CX88_VMUX_TELEVISION, 321 .type = CX88_VMUX_TELEVISION,
@@ -301,8 +337,11 @@ struct cx88_board cx88_boards[] = {
301 }, 337 },
302 [CX88_BOARD_ASUS_PVR_416] = { 338 [CX88_BOARD_ASUS_PVR_416] = {
303 .name = "ASUS PVR-416", 339 .name = "ASUS PVR-416",
304 .tuner_type = 43, 340 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
305 .tda9887_conf = TDA9887_PRESENT, 341 .radio_type = UNSET,
342 .tuner_addr = ADDR_UNSET,
343 .radio_addr = ADDR_UNSET,
344 .tda9887_conf = TDA9887_PRESENT,
306 .input = {{ 345 .input = {{
307 .type = CX88_VMUX_TELEVISION, 346 .type = CX88_VMUX_TELEVISION,
308 .vmux = 0, 347 .vmux = 0,
@@ -320,7 +359,10 @@ struct cx88_board cx88_boards[] = {
320 }, 359 },
321 [CX88_BOARD_MSI_TVANYWHERE] = { 360 [CX88_BOARD_MSI_TVANYWHERE] = {
322 .name = "MSI TV-@nywhere", 361 .name = "MSI TV-@nywhere",
323 .tuner_type = 33, 362 .tuner_type = TUNER_MT2032,
363 .radio_type = UNSET,
364 .tuner_addr = ADDR_UNSET,
365 .radio_addr = ADDR_UNSET,
324 .tda9887_conf = TDA9887_PRESENT, 366 .tda9887_conf = TDA9887_PRESENT,
325 .input = {{ 367 .input = {{
326 .type = CX88_VMUX_TELEVISION, 368 .type = CX88_VMUX_TELEVISION,
@@ -342,6 +384,9 @@ struct cx88_board cx88_boards[] = {
342 [CX88_BOARD_KWORLD_DVB_T] = { 384 [CX88_BOARD_KWORLD_DVB_T] = {
343 .name = "KWorld/VStream XPert DVB-T", 385 .name = "KWorld/VStream XPert DVB-T",
344 .tuner_type = TUNER_ABSENT, 386 .tuner_type = TUNER_ABSENT,
387 .radio_type = UNSET,
388 .tuner_addr = ADDR_UNSET,
389 .radio_addr = ADDR_UNSET,
345 .input = {{ 390 .input = {{
346 .type = CX88_VMUX_COMPOSITE1, 391 .type = CX88_VMUX_COMPOSITE1,
347 .vmux = 1, 392 .vmux = 1,
@@ -358,6 +403,9 @@ struct cx88_board cx88_boards[] = {
358 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1] = { 403 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1] = {
359 .name = "DVICO FusionHDTV DVB-T1", 404 .name = "DVICO FusionHDTV DVB-T1",
360 .tuner_type = TUNER_ABSENT, /* No analog tuner */ 405 .tuner_type = TUNER_ABSENT, /* No analog tuner */
406 .radio_type = UNSET,
407 .tuner_addr = ADDR_UNSET,
408 .radio_addr = ADDR_UNSET,
361 .input = {{ 409 .input = {{
362 .type = CX88_VMUX_COMPOSITE1, 410 .type = CX88_VMUX_COMPOSITE1,
363 .vmux = 1, 411 .vmux = 1,
@@ -371,7 +419,10 @@ struct cx88_board cx88_boards[] = {
371 }, 419 },
372 [CX88_BOARD_KWORLD_LTV883] = { 420 [CX88_BOARD_KWORLD_LTV883] = {
373 .name = "KWorld LTV883RF", 421 .name = "KWorld LTV883RF",
374 .tuner_type = 48, 422 .tuner_type = TUNER_TNF_8831BGFF,
423 .radio_type = UNSET,
424 .tuner_addr = ADDR_UNSET,
425 .radio_addr = ADDR_UNSET,
375 .input = {{ 426 .input = {{
376 .type = CX88_VMUX_TELEVISION, 427 .type = CX88_VMUX_TELEVISION,
377 .vmux = 0, 428 .vmux = 0,
@@ -397,6 +448,9 @@ struct cx88_board cx88_boards[] = {
397 [CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD] = { 448 [CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD] = {
398 .name = "DViCO - FusionHDTV 3 Gold", 449 .name = "DViCO - FusionHDTV 3 Gold",
399 .tuner_type = TUNER_MICROTUNE_4042FI5, 450 .tuner_type = TUNER_MICROTUNE_4042FI5,
451 .radio_type = UNSET,
452 .tuner_addr = ADDR_UNSET,
453 .radio_addr = ADDR_UNSET,
400 /* 454 /*
401 GPIO[0] resets DT3302 DTV receiver 455 GPIO[0] resets DT3302 DTV receiver
402 0 - reset asserted 456 0 - reset asserted
@@ -428,17 +482,14 @@ struct cx88_board cx88_boards[] = {
428 .vmux = 2, 482 .vmux = 2,
429 .gpio0 = 0x0f00, 483 .gpio0 = 0x0f00,
430 }}, 484 }},
431#if 0
432 .ts = {
433 .type = CX88_TS,
434 .gpio0 = 0x00000f01, /* Hooked to tuner reset bit */
435 }
436#endif
437 }, 485 },
438 [CX88_BOARD_HAUPPAUGE_DVB_T1] = { 486 [CX88_BOARD_HAUPPAUGE_DVB_T1] = {
439 .name = "Hauppauge Nova-T DVB-T", 487 .name = "Hauppauge Nova-T DVB-T",
440 .tuner_type = TUNER_ABSENT, 488 .tuner_type = TUNER_ABSENT,
441 .input = {{ 489 .radio_type = UNSET,
490 .tuner_addr = ADDR_UNSET,
491 .radio_addr = ADDR_UNSET,
492 .input = {{
442 .type = CX88_VMUX_DVB, 493 .type = CX88_VMUX_DVB,
443 .vmux = 0, 494 .vmux = 0,
444 }}, 495 }},
@@ -447,6 +498,9 @@ struct cx88_board cx88_boards[] = {
447 [CX88_BOARD_CONEXANT_DVB_T1] = { 498 [CX88_BOARD_CONEXANT_DVB_T1] = {
448 .name = "Conexant DVB-T reference design", 499 .name = "Conexant DVB-T reference design",
449 .tuner_type = TUNER_ABSENT, 500 .tuner_type = TUNER_ABSENT,
501 .radio_type = UNSET,
502 .tuner_addr = ADDR_UNSET,
503 .radio_addr = ADDR_UNSET,
450 .input = {{ 504 .input = {{
451 .type = CX88_VMUX_DVB, 505 .type = CX88_VMUX_DVB,
452 .vmux = 0, 506 .vmux = 0,
@@ -456,6 +510,9 @@ struct cx88_board cx88_boards[] = {
456 [CX88_BOARD_PROVIDEO_PV259] = { 510 [CX88_BOARD_PROVIDEO_PV259] = {
457 .name = "Provideo PV259", 511 .name = "Provideo PV259",
458 .tuner_type = TUNER_PHILIPS_FQ1216ME, 512 .tuner_type = TUNER_PHILIPS_FQ1216ME,
513 .radio_type = UNSET,
514 .tuner_addr = ADDR_UNSET,
515 .radio_addr = ADDR_UNSET,
459 .input = {{ 516 .input = {{
460 .type = CX88_VMUX_TELEVISION, 517 .type = CX88_VMUX_TELEVISION,
461 .vmux = 0, 518 .vmux = 0,
@@ -465,6 +522,9 @@ struct cx88_board cx88_boards[] = {
465 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS] = { 522 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS] = {
466 .name = "DVICO FusionHDTV DVB-T Plus", 523 .name = "DVICO FusionHDTV DVB-T Plus",
467 .tuner_type = TUNER_ABSENT, /* No analog tuner */ 524 .tuner_type = TUNER_ABSENT, /* No analog tuner */
525 .radio_type = UNSET,
526 .tuner_addr = ADDR_UNSET,
527 .radio_addr = ADDR_UNSET,
468 .input = {{ 528 .input = {{
469 .type = CX88_VMUX_COMPOSITE1, 529 .type = CX88_VMUX_COMPOSITE1,
470 .vmux = 1, 530 .vmux = 1,
@@ -479,6 +539,9 @@ struct cx88_board cx88_boards[] = {
479 [CX88_BOARD_DNTV_LIVE_DVB_T] = { 539 [CX88_BOARD_DNTV_LIVE_DVB_T] = {
480 .name = "digitalnow DNTV Live! DVB-T", 540 .name = "digitalnow DNTV Live! DVB-T",
481 .tuner_type = TUNER_ABSENT, 541 .tuner_type = TUNER_ABSENT,
542 .radio_type = UNSET,
543 .tuner_addr = ADDR_UNSET,
544 .radio_addr = ADDR_UNSET,
482 .input = {{ 545 .input = {{
483 .type = CX88_VMUX_COMPOSITE1, 546 .type = CX88_VMUX_COMPOSITE1,
484 .vmux = 1, 547 .vmux = 1,
@@ -495,6 +558,9 @@ struct cx88_board cx88_boards[] = {
495 [CX88_BOARD_PCHDTV_HD3000] = { 558 [CX88_BOARD_PCHDTV_HD3000] = {
496 .name = "pcHDTV HD3000 HDTV", 559 .name = "pcHDTV HD3000 HDTV",
497 .tuner_type = TUNER_THOMSON_DTT7610, 560 .tuner_type = TUNER_THOMSON_DTT7610,
561 .radio_type = UNSET,
562 .tuner_addr = ADDR_UNSET,
563 .radio_addr = ADDR_UNSET,
498 .input = {{ 564 .input = {{
499 .type = CX88_VMUX_TELEVISION, 565 .type = CX88_VMUX_TELEVISION,
500 .vmux = 0, 566 .vmux = 0,
@@ -530,8 +596,11 @@ struct cx88_board cx88_boards[] = {
530 [CX88_BOARD_HAUPPAUGE_ROSLYN] = { 596 [CX88_BOARD_HAUPPAUGE_ROSLYN] = {
531 // entry added by Kaustubh D. Bhalerao <bhalerao.1@osu.edu> 597 // entry added by Kaustubh D. Bhalerao <bhalerao.1@osu.edu>
532 // GPIO values obtained from regspy, courtesy Sean Covel 598 // GPIO values obtained from regspy, courtesy Sean Covel
533 .name = "Hauppauge WinTV 28xxx (Roslyn) models", 599 .name = "Hauppauge WinTV 28xxx (Roslyn) models",
534 .tuner_type = UNSET, 600 .tuner_type = UNSET,
601 .radio_type = UNSET,
602 .tuner_addr = ADDR_UNSET,
603 .radio_addr = ADDR_UNSET,
535 .input = {{ 604 .input = {{
536 .type = CX88_VMUX_TELEVISION, 605 .type = CX88_VMUX_TELEVISION,
537 .vmux = 0, 606 .vmux = 0,
@@ -559,33 +628,37 @@ struct cx88_board cx88_boards[] = {
559 .blackbird = 1, 628 .blackbird = 1,
560 }, 629 },
561 [CX88_BOARD_DIGITALLOGIC_MEC] = { 630 [CX88_BOARD_DIGITALLOGIC_MEC] = {
562 /* params copied over from Leadtek PVR 2000 */
563 .name = "Digital-Logic MICROSPACE Entertainment Center (MEC)", 631 .name = "Digital-Logic MICROSPACE Entertainment Center (MEC)",
564 /* not sure yet about the tuner type */ 632 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
565 .tuner_type = 38, 633 .radio_type = UNSET,
634 .tuner_addr = ADDR_UNSET,
635 .radio_addr = ADDR_UNSET,
566 .tda9887_conf = TDA9887_PRESENT, 636 .tda9887_conf = TDA9887_PRESENT,
567 .input = {{ 637 .input = {{
568 .type = CX88_VMUX_TELEVISION, 638 .type = CX88_VMUX_TELEVISION,
569 .vmux = 0, 639 .vmux = 0,
570 .gpio0 = 0x0000bde6, 640 .gpio0 = 0x00009d80,
571 },{ 641 },{
572 .type = CX88_VMUX_COMPOSITE1, 642 .type = CX88_VMUX_COMPOSITE1,
573 .vmux = 1, 643 .vmux = 1,
574 .gpio0 = 0x0000bde6, 644 .gpio0 = 0x00009d76,
575 },{ 645 },{
576 .type = CX88_VMUX_SVIDEO, 646 .type = CX88_VMUX_SVIDEO,
577 .vmux = 2, 647 .vmux = 2,
578 .gpio0 = 0x0000bde6, 648 .gpio0 = 0x00009d76,
579 }}, 649 }},
580 .radio = { 650 .radio = {
581 .type = CX88_RADIO, 651 .type = CX88_RADIO,
582 .gpio0 = 0x0000bd62, 652 .gpio0 = 0x00009d00,
583 }, 653 },
584 .blackbird = 1, 654 .blackbird = 1,
585 }, 655 },
586 [CX88_BOARD_IODATA_GVBCTV7E] = { 656 [CX88_BOARD_IODATA_GVBCTV7E] = {
587 .name = "IODATA GV/BCTV7E", 657 .name = "IODATA GV/BCTV7E",
588 .tuner_type = TUNER_PHILIPS_FQ1286, 658 .tuner_type = TUNER_PHILIPS_FQ1286,
659 .radio_type = UNSET,
660 .tuner_addr = ADDR_UNSET,
661 .radio_addr = ADDR_UNSET,
589 .tda9887_conf = TDA9887_PRESENT, 662 .tda9887_conf = TDA9887_PRESENT,
590 .input = {{ 663 .input = {{
591 .type = CX88_VMUX_TELEVISION, 664 .type = CX88_VMUX_TELEVISION,
@@ -601,6 +674,56 @@ struct cx88_board cx88_boards[] = {
601 .gpio1 = 0x0000e07f, 674 .gpio1 = 0x0000e07f,
602 }} 675 }}
603 }, 676 },
677 [CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO] = {
678 .name = "PixelView PlayTV Ultra Pro (Stereo)",
679 /* May be also TUNER_YMEC_TVF_5533MF for NTSC/M or PAL/M */
680 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
681 .radio_type = TUNER_TEA5767,
682 .tuner_addr = 0xc2>>1,
683 .radio_addr = 0xc0>>1,
684 .input = {{
685 .type = CX88_VMUX_TELEVISION,
686 .vmux = 0,
687 .gpio0 = 0xbf61, /* internal decoder */
688 },{
689 .type = CX88_VMUX_COMPOSITE1,
690 .vmux = 1,
691 .gpio0 = 0xbf63,
692 },{
693 .type = CX88_VMUX_SVIDEO,
694 .vmux = 2,
695 .gpio0 = 0xbf63,
696 }},
697 .radio = {
698 .type = CX88_RADIO,
699 .gpio0 = 0xbf60,
700 },
701 },
702 [CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T] = {
703 .name = "DViCO - FusionHDTV 3 Gold-T",
704 .tuner_type = TUNER_THOMSON_DTT7611,
705 .radio_type = UNSET,
706 .tuner_addr = ADDR_UNSET,
707 .radio_addr = ADDR_UNSET,
708 /* See DViCO FusionHDTV 3 Gold for GPIO documentation. */
709 .input = {{
710 .type = CX88_VMUX_TELEVISION,
711 .vmux = 0,
712 .gpio0 = 0x0f0d,
713 },{
714 .type = CX88_VMUX_CABLE,
715 .vmux = 0,
716 .gpio0 = 0x0f05,
717 },{
718 .type = CX88_VMUX_COMPOSITE1,
719 .vmux = 1,
720 .gpio0 = 0x0f00,
721 },{
722 .type = CX88_VMUX_SVIDEO,
723 .vmux = 2,
724 .gpio0 = 0x0f00,
725 }},
726 },
604}; 727};
605const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards); 728const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
606 729
@@ -673,6 +796,10 @@ struct cx88_subid cx88_subids[] = {
673 .subdevice = 0xd810, 796 .subdevice = 0xd810,
674 .card = CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD, 797 .card = CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD,
675 },{ 798 },{
799 .subvendor = 0x18ac,
800 .subdevice = 0xd820,
801 .card = CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T,
802 },{
676 .subvendor = 0x18AC, 803 .subvendor = 0x18AC,
677 .subdevice = 0xDB00, 804 .subdevice = 0xDB00,
678 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1, 805 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1,
@@ -935,4 +1062,5 @@ EXPORT_SYMBOL(cx88_card_setup);
935 * Local variables: 1062 * Local variables:
936 * c-basic-offset: 8 1063 * c-basic-offset: 8
937 * End: 1064 * End:
1065 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
938 */ 1066 */
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 1ff79b5a8835..c046a23537d3 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-core.c,v 1.24 2005/01/19 12:01:55 kraxel Exp $ 2 * $Id: cx88-core.c,v 1.28 2005/06/12 04:19:19 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * driver core 5 * driver core
@@ -51,12 +51,15 @@ module_param(latency,int,0444);
51MODULE_PARM_DESC(latency,"pci latency timer"); 51MODULE_PARM_DESC(latency,"pci latency timer");
52 52
53static unsigned int tuner[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; 53static unsigned int tuner[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
54static unsigned int radio[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
54static unsigned int card[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET }; 55static unsigned int card[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
55 56
56module_param_array(tuner, int, NULL, 0444); 57module_param_array(tuner, int, NULL, 0444);
58module_param_array(radio, int, NULL, 0444);
57module_param_array(card, int, NULL, 0444); 59module_param_array(card, int, NULL, 0444);
58 60
59MODULE_PARM_DESC(tuner,"tuner type"); 61MODULE_PARM_DESC(tuner,"tuner type");
62MODULE_PARM_DESC(radio,"radio tuner type");
60MODULE_PARM_DESC(card,"card type"); 63MODULE_PARM_DESC(card,"card type");
61 64
62static unsigned int nicam = 0; 65static unsigned int nicam = 0;
@@ -429,7 +432,7 @@ int cx88_sram_channel_setup(struct cx88_core *core,
429/* ------------------------------------------------------------------ */ 432/* ------------------------------------------------------------------ */
430/* debug helper code */ 433/* debug helper code */
431 434
432static int cx88_risc_decode(u32 risc) 435int cx88_risc_decode(u32 risc)
433{ 436{
434 static char *instr[16] = { 437 static char *instr[16] = {
435 [ RISC_SYNC >> 28 ] = "sync", 438 [ RISC_SYNC >> 28 ] = "sync",
@@ -736,6 +739,10 @@ static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm)
736{ 739{
737 static const unsigned int ntsc = 28636360; 740 static const unsigned int ntsc = 28636360;
738 static const unsigned int pal = 35468950; 741 static const unsigned int pal = 35468950;
742 static const unsigned int palm = 28604892;
743
744 if (norm->id & V4L2_STD_PAL_M)
745 return palm;
739 746
740 return (norm->id & V4L2_STD_625_50) ? pal : ntsc; 747 return (norm->id & V4L2_STD_625_50) ? pal : ntsc;
741} 748}
@@ -749,6 +756,11 @@ static unsigned int inline norm_notchfilter(struct cx88_tvnorm *norm)
749 756
750static unsigned int inline norm_htotal(struct cx88_tvnorm *norm) 757static unsigned int inline norm_htotal(struct cx88_tvnorm *norm)
751{ 758{
759 /* Should always be Line Draw Time / (4*FSC) */
760
761 if (norm->id & V4L2_STD_PAL_M)
762 return 909;
763
752 return (norm->id & V4L2_STD_625_50) ? 1135 : 910; 764 return (norm->id & V4L2_STD_625_50) ? 1135 : 910;
753} 765}
754 766
@@ -1164,8 +1176,20 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
1164 "insmod option" : "autodetected"); 1176 "insmod option" : "autodetected");
1165 1177
1166 core->tuner_type = tuner[core->nr]; 1178 core->tuner_type = tuner[core->nr];
1179 core->radio_type = radio[core->nr];
1167 if (UNSET == core->tuner_type) 1180 if (UNSET == core->tuner_type)
1168 core->tuner_type = cx88_boards[core->board].tuner_type; 1181 core->tuner_type = cx88_boards[core->board].tuner_type;
1182 if (UNSET == core->radio_type)
1183 core->radio_type = cx88_boards[core->board].radio_type;
1184 if (!core->tuner_addr)
1185 core->tuner_addr = cx88_boards[core->board].tuner_addr;
1186 if (!core->radio_addr)
1187 core->radio_addr = cx88_boards[core->board].radio_addr;
1188
1189 printk(KERN_INFO "TV tuner %d at 0x%02x, Radio tuner %d at 0x%02x\n",
1190 core->tuner_type, core->tuner_addr<<1,
1191 core->radio_type, core->radio_addr<<1);
1192
1169 core->tda9887_conf = cx88_boards[core->board].tda9887_conf; 1193 core->tda9887_conf = cx88_boards[core->board].tda9887_conf;
1170 1194
1171 /* init hardware */ 1195 /* init hardware */
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 9d15d3d5a2b7..1a259c3966cd 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-dvb.c,v 1.31 2005/03/07 15:58:05 kraxel Exp $ 2 * $Id: cx88-dvb.c,v 1.33 2005/06/12 04:19:19 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * MPEG Transport Stream (DVB) routines 5 * MPEG Transport Stream (DVB) routines
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 0725b1288f4f..e20adefcfc6c 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-i2c.c,v 1.20 2005/02/15 15:59:35 kraxel Exp $ 2 $Id: cx88-i2c.c,v 1.23 2005/06/12 04:19:19 mchehab Exp $
3 3
4 cx88-i2c.c -- all the i2c code is here 4 cx88-i2c.c -- all the i2c code is here
5 5
@@ -91,6 +91,7 @@ static int cx8800_bit_getsda(void *data)
91 91
92static int attach_inform(struct i2c_client *client) 92static int attach_inform(struct i2c_client *client)
93{ 93{
94 struct tuner_addr tun_addr;
94 struct cx88_core *core = i2c_get_adapdata(client->adapter); 95 struct cx88_core *core = i2c_get_adapdata(client->adapter);
95 96
96 dprintk(1, "i2c attach [addr=0x%x,client=%s]\n", 97 dprintk(1, "i2c attach [addr=0x%x,client=%s]\n",
@@ -98,8 +99,19 @@ static int attach_inform(struct i2c_client *client)
98 if (!client->driver->command) 99 if (!client->driver->command)
99 return 0; 100 return 0;
100 101
101 if (core->tuner_type != UNSET) 102 if (core->radio_type != UNSET) {
102 client->driver->command(client, TUNER_SET_TYPE, &core->tuner_type); 103 tun_addr.v4l2_tuner = V4L2_TUNER_RADIO;
104 tun_addr.type = core->radio_type;
105 tun_addr.addr = core->radio_addr;
106 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_addr);
107 }
108 if (core->tuner_type != UNSET) {
109 tun_addr.v4l2_tuner = V4L2_TUNER_ANALOG_TV;
110 tun_addr.type = core->tuner_type;
111 tun_addr.addr = core->tuner_addr;
112 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_addr);
113 }
114
103 if (core->tda9887_conf) 115 if (core->tda9887_conf)
104 client->driver->command(client, TDA9887_SET_CONFIG, &core->tda9887_conf); 116 client->driver->command(client, TDA9887_SET_CONFIG, &core->tda9887_conf);
105 return 0; 117 return 0;
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index af6ad8cdbdb7..dc0dcf249aac 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-input.c,v 1.9 2005/03/04 09:12:23 kraxel Exp $ 2 * $Id: cx88-input.c,v 1.11 2005/05/22 20:57:56 nsh Exp $
3 * 3 *
4 * Device driver for GPIO attached remote control interfaces 4 * Device driver for GPIO attached remote control interfaces
5 * on Conexant 2388x based TV/DVB cards. 5 * on Conexant 2388x based TV/DVB cards.
@@ -235,6 +235,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
235 /* detect & configure */ 235 /* detect & configure */
236 switch (core->board) { 236 switch (core->board) {
237 case CX88_BOARD_DNTV_LIVE_DVB_T: 237 case CX88_BOARD_DNTV_LIVE_DVB_T:
238 case CX88_BOARD_KWORLD_DVB_T:
238 ir_codes = ir_codes_dntv_live_dvb_t; 239 ir_codes = ir_codes_dntv_live_dvb_t;
239 ir->gpio_addr = MO_GP1_IO; 240 ir->gpio_addr = MO_GP1_IO;
240 ir->mask_keycode = 0x1f; 241 ir->mask_keycode = 0x1f;
@@ -261,7 +262,15 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
261 ir->mask_keydown = 0x02; 262 ir->mask_keydown = 0x02;
262 ir->polling = 5; // ms 263 ir->polling = 5; // ms
263 break; 264 break;
265 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
266 ir_codes = ir_codes_pixelview;
267 ir->gpio_addr = MO_GP1_IO;
268 ir->mask_keycode = 0x1f;
269 ir->mask_keyup = 0x80;
270 ir->polling = 1; // ms
271 break;
264 } 272 }
273
265 if (NULL == ir_codes) { 274 if (NULL == ir_codes) {
266 kfree(ir); 275 kfree(ir);
267 return -ENODEV; 276 return -ENODEV;
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index 07aae1899e17..9ade2ae91e9b 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-mpeg.c,v 1.25 2005/03/07 14:18:00 kraxel Exp $ 2 * $Id: cx88-mpeg.c,v 1.26 2005/06/03 13:31:51 mchehab Exp $
3 * 3 *
4 * Support for the mpeg transport stream transfers 4 * Support for the mpeg transport stream transfers
5 * PCI function #2 of the cx2388x. 5 * PCI function #2 of the cx2388x.
@@ -55,7 +55,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
55{ 55{
56 struct cx88_core *core = dev->core; 56 struct cx88_core *core = dev->core;
57 57
58 dprintk(1, "cx8802_start_mpegport_dma %d\n", buf->vb.width); 58 dprintk(0, "cx8802_start_dma %d\n", buf->vb.width);
59 59
60 /* setup fifo + format */ 60 /* setup fifo + format */
61 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28], 61 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28],
@@ -100,18 +100,21 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
100 q->count = 1; 100 q->count = 1;
101 101
102 /* enable irqs */ 102 /* enable irqs */
103 dprintk( 0, "setting the interrupt mask\n" );
103 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04); 104 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04);
104 cx_write(MO_TS_INTMSK, 0x1f0011); 105 cx_set(MO_TS_INTMSK, 0x1f0011);
106 //cx_write(MO_TS_INTMSK, 0x0f0011);
105 107
106 /* start dma */ 108 /* start dma */
107 cx_write(MO_DEV_CNTRL2, (1<<5)); /* FIXME: s/write/set/ ??? */ 109 cx_set(MO_DEV_CNTRL2, (1<<5));
108 cx_write(MO_TS_DMACNTRL, 0x11); 110 cx_set(MO_TS_DMACNTRL, 0x11);
109 return 0; 111 return 0;
110} 112}
111 113
112static int cx8802_stop_dma(struct cx8802_dev *dev) 114static int cx8802_stop_dma(struct cx8802_dev *dev)
113{ 115{
114 struct cx88_core *core = dev->core; 116 struct cx88_core *core = dev->core;
117 dprintk( 0, "cx8802_stop_dma\n" );
115 118
116 /* stop dma */ 119 /* stop dma */
117 cx_clear(MO_TS_DMACNTRL, 0x11); 120 cx_clear(MO_TS_DMACNTRL, 0x11);
@@ -131,8 +134,12 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
131 struct cx88_buffer *buf; 134 struct cx88_buffer *buf;
132 struct list_head *item; 135 struct list_head *item;
133 136
137 dprintk( 0, "cx8802_restart_queue\n" );
134 if (list_empty(&q->active)) 138 if (list_empty(&q->active))
139 {
140 dprintk( 0, "cx8802_restart_queue: queue is empty\n" );
135 return 0; 141 return 0;
142 }
136 143
137 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); 144 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
138 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 145 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
@@ -182,27 +189,32 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
182 struct cx88_buffer *prev; 189 struct cx88_buffer *prev;
183 struct cx88_dmaqueue *q = &dev->mpegq; 190 struct cx88_dmaqueue *q = &dev->mpegq;
184 191
192 dprintk( 1, "cx8802_buf_queue\n" );
185 /* add jump to stopper */ 193 /* add jump to stopper */
186 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); 194 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
187 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); 195 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
188 196
189 if (list_empty(&q->active)) { 197 if (list_empty(&q->active)) {
198 dprintk( 0, "queue is empty - first active\n" );
190 list_add_tail(&buf->vb.queue,&q->active); 199 list_add_tail(&buf->vb.queue,&q->active);
191 cx8802_start_dma(dev, q, buf); 200 cx8802_start_dma(dev, q, buf);
192 buf->vb.state = STATE_ACTIVE; 201 buf->vb.state = STATE_ACTIVE;
193 buf->count = q->count++; 202 buf->count = q->count++;
194 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 203 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
195 dprintk(2,"[%p/%d] %s - first active\n", 204 dprintk(0,"[%p/%d] %s - first active\n",
196 buf, buf->vb.i, __FUNCTION__); 205 buf, buf->vb.i, __FUNCTION__);
206 //udelay(100);
197 207
198 } else { 208 } else {
209 dprintk( 1, "queue is not empty - append to active\n" );
199 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); 210 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
200 list_add_tail(&buf->vb.queue,&q->active); 211 list_add_tail(&buf->vb.queue,&q->active);
201 buf->vb.state = STATE_ACTIVE; 212 buf->vb.state = STATE_ACTIVE;
202 buf->count = q->count++; 213 buf->count = q->count++;
203 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 214 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
204 dprintk(2,"[%p/%d] %s - append to active\n", 215 dprintk( 1, "[%p/%d] %s - append to active\n",
205 buf, buf->vb.i, __FUNCTION__); 216 buf, buf->vb.i, __FUNCTION__);
217 //udelay(100);
206 } 218 }
207} 219}
208 220
@@ -224,7 +236,10 @@ static void do_cancel_buffers(struct cx8802_dev *dev, char *reason, int restart)
224 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma); 236 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma);
225 } 237 }
226 if (restart) 238 if (restart)
239 {
240 dprintk(0, "restarting queue\n" );
227 cx8802_restart_queue(dev,q); 241 cx8802_restart_queue(dev,q);
242 }
228 spin_unlock_irqrestore(&dev->slock,flags); 243 spin_unlock_irqrestore(&dev->slock,flags);
229} 244}
230 245
@@ -232,6 +247,7 @@ void cx8802_cancel_buffers(struct cx8802_dev *dev)
232{ 247{
233 struct cx88_dmaqueue *q = &dev->mpegq; 248 struct cx88_dmaqueue *q = &dev->mpegq;
234 249
250 dprintk( 1, "cx8802_cancel_buffers" );
235 del_timer_sync(&q->timeout); 251 del_timer_sync(&q->timeout);
236 cx8802_stop_dma(dev); 252 cx8802_stop_dma(dev);
237 do_cancel_buffers(dev,"cancel",0); 253 do_cancel_buffers(dev,"cancel",0);
@@ -241,7 +257,7 @@ static void cx8802_timeout(unsigned long data)
241{ 257{
242 struct cx8802_dev *dev = (struct cx8802_dev*)data; 258 struct cx8802_dev *dev = (struct cx8802_dev*)data;
243 259
244 dprintk(1, "%s\n",__FUNCTION__); 260 dprintk(0, "%s\n",__FUNCTION__);
245 261
246 if (debug) 262 if (debug)
247 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]); 263 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
@@ -254,12 +270,17 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev)
254 struct cx88_core *core = dev->core; 270 struct cx88_core *core = dev->core;
255 u32 status, mask, count; 271 u32 status, mask, count;
256 272
273 dprintk( 1, "cx8802_mpeg_irq\n" );
257 status = cx_read(MO_TS_INTSTAT); 274 status = cx_read(MO_TS_INTSTAT);
258 mask = cx_read(MO_TS_INTMSK); 275 mask = cx_read(MO_TS_INTMSK);
259 if (0 == (status & mask)) 276 if (0 == (status & mask))
260 return; 277 return;
261 278
262 cx_write(MO_TS_INTSTAT, status); 279 cx_write(MO_TS_INTSTAT, status);
280#if 0
281 cx88_print_irqbits(core->name, "irq mpeg ",
282 cx88_mpeg_irqs, status, mask);
283#endif
263 if (debug || (status & mask & ~0xff)) 284 if (debug || (status & mask & ~0xff))
264 cx88_print_irqbits(core->name, "irq mpeg ", 285 cx88_print_irqbits(core->name, "irq mpeg ",
265 cx88_mpeg_irqs, status, mask); 286 cx88_mpeg_irqs, status, mask);
@@ -273,6 +294,7 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev)
273 294
274 /* risc1 y */ 295 /* risc1 y */
275 if (status & 0x01) { 296 if (status & 0x01) {
297 dprintk( 1, "wake up\n" );
276 spin_lock(&dev->slock); 298 spin_lock(&dev->slock);
277 count = cx_read(MO_TS_GPCNT); 299 count = cx_read(MO_TS_GPCNT);
278 cx88_wakeup(dev->core, &dev->mpegq, count); 300 cx88_wakeup(dev->core, &dev->mpegq, count);
@@ -288,6 +310,7 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev)
288 310
289 /* other general errors */ 311 /* other general errors */
290 if (status & 0x1f0100) { 312 if (status & 0x1f0100) {
313 dprintk( 0, "general errors: 0x%08x\n", status & 0x1f0100 );
291 spin_lock(&dev->slock); 314 spin_lock(&dev->slock);
292 cx8802_stop_dma(dev); 315 cx8802_stop_dma(dev);
293 cx8802_restart_queue(dev,&dev->mpegq); 316 cx8802_restart_queue(dev,&dev->mpegq);
@@ -295,6 +318,8 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev)
295 } 318 }
296} 319}
297 320
321#define MAX_IRQ_LOOP 10
322
298static irqreturn_t cx8802_irq(int irq, void *dev_id, struct pt_regs *regs) 323static irqreturn_t cx8802_irq(int irq, void *dev_id, struct pt_regs *regs)
299{ 324{
300 struct cx8802_dev *dev = dev_id; 325 struct cx8802_dev *dev = dev_id;
@@ -302,10 +327,13 @@ static irqreturn_t cx8802_irq(int irq, void *dev_id, struct pt_regs *regs)
302 u32 status; 327 u32 status;
303 int loop, handled = 0; 328 int loop, handled = 0;
304 329
305 for (loop = 0; loop < 10; loop++) { 330 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
306 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x04); 331 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x04);
307 if (0 == status) 332 if (0 == status)
308 goto out; 333 goto out;
334 dprintk( 1, "cx8802_irq\n" );
335 dprintk( 1, " loop: %d/%d\n", loop, MAX_IRQ_LOOP );
336 dprintk( 1, " status: %d\n", status );
309 handled = 1; 337 handled = 1;
310 cx_write(MO_PCI_INTSTAT, status); 338 cx_write(MO_PCI_INTSTAT, status);
311 339
@@ -314,7 +342,8 @@ static irqreturn_t cx8802_irq(int irq, void *dev_id, struct pt_regs *regs)
314 if (status & 0x04) 342 if (status & 0x04)
315 cx8802_mpeg_irq(dev); 343 cx8802_mpeg_irq(dev);
316 }; 344 };
317 if (10 == loop) { 345 if (MAX_IRQ_LOOP == loop) {
346 dprintk( 0, "clearing mask\n" );
318 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n", 347 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
319 core->name); 348 core->name);
320 cx_write(MO_PCI_INTMSK,0); 349 cx_write(MO_PCI_INTMSK,0);
@@ -378,6 +407,7 @@ int cx8802_init_common(struct cx8802_dev *dev)
378 407
379void cx8802_fini_common(struct cx8802_dev *dev) 408void cx8802_fini_common(struct cx8802_dev *dev)
380{ 409{
410 dprintk( 2, "cx8802_fini_common\n" );
381 cx8802_stop_dma(dev); 411 cx8802_stop_dma(dev);
382 pci_disable_device(dev->pci); 412 pci_disable_device(dev->pci);
383 413
@@ -399,6 +429,7 @@ int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
399 /* stop mpeg dma */ 429 /* stop mpeg dma */
400 spin_lock(&dev->slock); 430 spin_lock(&dev->slock);
401 if (!list_empty(&dev->mpegq.active)) { 431 if (!list_empty(&dev->mpegq.active)) {
432 dprintk( 2, "suspend\n" );
402 printk("%s: suspend mpeg\n", core->name); 433 printk("%s: suspend mpeg\n", core->name);
403 cx8802_stop_dma(dev); 434 cx8802_stop_dma(dev);
404 del_timer(&dev->mpegq.timeout); 435 del_timer(&dev->mpegq.timeout);
@@ -463,4 +494,5 @@ EXPORT_SYMBOL(cx8802_resume_common);
463 * Local variables: 494 * Local variables:
464 * c-basic-offset: 8 495 * c-basic-offset: 8
465 * End: 496 * End:
497 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
466 */ 498 */
diff --git a/drivers/media/video/cx88/cx88-reg.h b/drivers/media/video/cx88/cx88-reg.h
index 8638ce57d84c..63ad33f5818b 100644
--- a/drivers/media/video/cx88/cx88-reg.h
+++ b/drivers/media/video/cx88/cx88-reg.h
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-reg.h,v 1.6 2004/10/13 10:39:00 kraxel Exp $ 2 $Id: cx88-reg.h,v 1.7 2005/06/03 13:31:51 mchehab Exp $
3 3
4 cx88x-hw.h - CX2388x register offsets 4 cx88x-hw.h - CX2388x register offsets
5 5
@@ -397,6 +397,7 @@
397#define AUD_RATE_ADJ4 0x3205e4 397#define AUD_RATE_ADJ4 0x3205e4
398#define AUD_RATE_ADJ5 0x3205e8 398#define AUD_RATE_ADJ5 0x3205e8
399#define AUD_APB_IN_RATE_ADJ 0x3205ec 399#define AUD_APB_IN_RATE_ADJ 0x3205ec
400#define AUD_I2SCNTL 0x3205ec
400#define AUD_PHASE_FIX_CTL 0x3205f0 401#define AUD_PHASE_FIX_CTL 0x3205f0
401#define AUD_PLL_PRESCALE 0x320600 402#define AUD_PLL_PRESCALE 0x320600
402#define AUD_PLL_DDS 0x320604 403#define AUD_PLL_DDS 0x320604
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index f2a9475a2fee..46d78b1dc9b2 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-tvaudio.c,v 1.34 2005/03/07 16:10:51 kraxel Exp $ 2 $Id: cx88-tvaudio.c,v 1.36 2005/06/05 05:53:45 mchehab Exp $
3 3
4 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver 4 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
5 5
@@ -127,7 +127,8 @@ static void set_audio_start(struct cx88_core *core,
127 cx_write(AUD_VOL_CTL, (1 << 6)); 127 cx_write(AUD_VOL_CTL, (1 << 6));
128 128
129 // increase level of input by 12dB 129 // increase level of input by 12dB
130 cx_write(AUD_AFE_12DB_EN, 0x0001); 130// cx_write(AUD_AFE_12DB_EN, 0x0001);
131 cx_write(AUD_AFE_12DB_EN, 0x0000);
131 132
132 // start programming 133 // start programming
133 cx_write(AUD_CTL, 0x0000); 134 cx_write(AUD_CTL, 0x0000);
@@ -143,9 +144,15 @@ static void set_audio_finish(struct cx88_core *core)
143 u32 volume; 144 u32 volume;
144 145
145 if (cx88_boards[core->board].blackbird) { 146 if (cx88_boards[core->board].blackbird) {
147 // sets sound input from external adc
148 cx_set(AUD_CTL, EN_I2SIN_ENABLE);
149 //cx_write(AUD_I2SINPUTCNTL, 0);
150 cx_write(AUD_I2SINPUTCNTL, 4);
151 cx_write(AUD_BAUDRATE, 1);
146 // 'pass-thru mode': this enables the i2s output to the mpeg encoder 152 // 'pass-thru mode': this enables the i2s output to the mpeg encoder
147 cx_set(AUD_CTL, 0x2000); 153 cx_set(AUD_CTL, EN_I2SOUT_ENABLE);
148 cx_write(AUD_I2SOUTPUTCNTL, 1); 154 cx_write(AUD_I2SOUTPUTCNTL, 1);
155 cx_write(AUD_I2SCNTL, 0);
149 //cx_write(AUD_APB_IN_RATE_ADJ, 0); 156 //cx_write(AUD_APB_IN_RATE_ADJ, 0);
150 } 157 }
151 158
@@ -707,50 +714,65 @@ static void set_audio_standard_EIAJ(struct cx88_core *core)
707 set_audio_finish(core); 714 set_audio_finish(core);
708} 715}
709 716
710static void set_audio_standard_FM(struct cx88_core *core) 717static void set_audio_standard_FM(struct cx88_core *core, enum cx88_deemph_type deemph)
711{ 718{
712#if 0 /* FIXME */ 719 static const struct rlist fm_deemph_50[] = {
713 switch (dev->audio_properties.FM_deemphasis) 720 { AUD_DEEMPH0_G0, 0x0C45 },
714 { 721 { AUD_DEEMPH0_A0, 0x6262 },
715 case WW_FM_DEEMPH_50: 722 { AUD_DEEMPH0_B0, 0x1C29 },
716 //Set De-emphasis filter coefficients for 50 usec 723 { AUD_DEEMPH0_A1, 0x3FC66},
717 cx_write(AUD_DEEMPH0_G0, 0x0C45); 724 { AUD_DEEMPH0_B1, 0x399A },
718 cx_write(AUD_DEEMPH0_A0, 0x6262); 725
719 cx_write(AUD_DEEMPH0_B0, 0x1C29); 726 { AUD_DEEMPH1_G0, 0x0D80 },
720 cx_write(AUD_DEEMPH0_A1, 0x3FC66); 727 { AUD_DEEMPH1_A0, 0x6262 },
721 cx_write(AUD_DEEMPH0_B1, 0x399A); 728 { AUD_DEEMPH1_B0, 0x1C29 },
722 729 { AUD_DEEMPH1_A1, 0x3FC66},
723 cx_write(AUD_DEEMPH1_G0, 0x0D80); 730 { AUD_DEEMPH1_B1, 0x399A},
724 cx_write(AUD_DEEMPH1_A0, 0x6262); 731
725 cx_write(AUD_DEEMPH1_B0, 0x1C29); 732 { AUD_POLYPH80SCALEFAC, 0x0003},
726 cx_write(AUD_DEEMPH1_A1, 0x3FC66); 733 { /* end of list */ },
727 cx_write(AUD_DEEMPH1_B1, 0x399A); 734 };
735 static const struct rlist fm_deemph_75[] = {
736 { AUD_DEEMPH0_G0, 0x091B },
737 { AUD_DEEMPH0_A0, 0x6B68 },
738 { AUD_DEEMPH0_B0, 0x11EC },
739 { AUD_DEEMPH0_A1, 0x3FC66},
740 { AUD_DEEMPH0_B1, 0x399A },
741
742 { AUD_DEEMPH1_G0, 0x0AA0 },
743 { AUD_DEEMPH1_A0, 0x6B68 },
744 { AUD_DEEMPH1_B0, 0x11EC },
745 { AUD_DEEMPH1_A1, 0x3FC66},
746 { AUD_DEEMPH1_B1, 0x399A},
747
748 { AUD_POLYPH80SCALEFAC, 0x0003},
749 { /* end of list */ },
750 };
728 751
729 break; 752 /* It is enough to leave default values? */
753 static const struct rlist fm_no_deemph[] = {
730 754
731 case WW_FM_DEEMPH_75: 755 { AUD_POLYPH80SCALEFAC, 0x0003},
732 //Set De-emphasis filter coefficients for 75 usec 756 { /* end of list */ },
733 cx_write(AUD_DEEMPH0_G0, 0x91B ); 757 };
734 cx_write(AUD_DEEMPH0_A0, 0x6B68);
735 cx_write(AUD_DEEMPH0_B0, 0x11EC);
736 cx_write(AUD_DEEMPH0_A1, 0x3FC66);
737 cx_write(AUD_DEEMPH0_B1, 0x399A);
738 758
739 cx_write(AUD_DEEMPH1_G0, 0xAA0 ); 759 dprintk("%s (status: unknown)\n",__FUNCTION__);
740 cx_write(AUD_DEEMPH1_A0, 0x6B68); 760 set_audio_start(core, 0x0020, EN_FMRADIO_AUTO_STEREO);
741 cx_write(AUD_DEEMPH1_B0, 0x11EC);
742 cx_write(AUD_DEEMPH1_A1, 0x3FC66);
743 cx_write(AUD_DEEMPH1_B1, 0x399A);
744 761
762 switch (deemph)
763 {
764 case FM_NO_DEEMPH:
765 set_audio_registers(core, fm_no_deemph);
745 break; 766 break;
746 }
747#endif
748 767
749 dprintk("%s (status: unknown)\n",__FUNCTION__); 768 case FM_DEEMPH_50:
750 set_audio_start(core, 0x0020, EN_FMRADIO_AUTO_STEREO); 769 set_audio_registers(core, fm_deemph_50);
770 break;
751 771
752 // AB: 10/2/01: this register is not being reset appropriately on occasion. 772 case FM_DEEMPH_75:
753 cx_write(AUD_POLYPH80SCALEFAC,3); 773 set_audio_registers(core, fm_deemph_75);
774 break;
775 }
754 776
755 set_audio_finish(core); 777 set_audio_finish(core);
756} 778}
@@ -778,7 +800,7 @@ void cx88_set_tvaudio(struct cx88_core *core)
778 set_audio_standard_EIAJ(core); 800 set_audio_standard_EIAJ(core);
779 break; 801 break;
780 case WW_FM: 802 case WW_FM:
781 set_audio_standard_FM(core); 803 set_audio_standard_FM(core,FM_NO_DEEMPH);
782 break; 804 break;
783 case WW_SYSTEM_L_AM: 805 case WW_SYSTEM_L_AM:
784 set_audio_standard_NICAM_L(core, 1); 806 set_audio_standard_NICAM_L(core, 1);
@@ -1029,4 +1051,5 @@ EXPORT_SYMBOL(cx88_audio_thread);
1029 * Local variables: 1051 * Local variables:
1030 * c-basic-offset: 8 1052 * c-basic-offset: 8
1031 * End: 1053 * End:
1054 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
1032 */ 1055 */
diff --git a/drivers/media/video/cx88/cx88-vbi.c b/drivers/media/video/cx88/cx88-vbi.c
index 0584ff476387..320d57888bbd 100644
--- a/drivers/media/video/cx88/cx88-vbi.c
+++ b/drivers/media/video/cx88/cx88-vbi.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-vbi.c,v 1.16 2004/12/10 12:33:39 kraxel Exp $ 2 * $Id: cx88-vbi.c,v 1.17 2005/06/12 04:19:19 mchehab Exp $
3 */ 3 */
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5#include <linux/module.h> 5#include <linux/module.h>
@@ -47,8 +47,8 @@ void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f)
47} 47}
48 48
49static int cx8800_start_vbi_dma(struct cx8800_dev *dev, 49static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
50 struct cx88_dmaqueue *q, 50 struct cx88_dmaqueue *q,
51 struct cx88_buffer *buf) 51 struct cx88_buffer *buf)
52{ 52{
53 struct cx88_core *core = dev->core; 53 struct cx88_core *core = dev->core;
54 54
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index d1f5c92f0ce5..e4ca7350df15 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-video.c,v 1.58 2005/03/07 15:58:05 kraxel Exp $ 2 * $Id: cx88-video.c,v 1.63 2005/06/12 04:19:19 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -1187,9 +1187,24 @@ static void init_controls(struct cx8800_dev *dev)
1187 .id = V4L2_CID_AUDIO_VOLUME, 1187 .id = V4L2_CID_AUDIO_VOLUME,
1188 .value = 0x3f, 1188 .value = 0x3f,
1189 }; 1189 };
1190 static struct v4l2_control hue = {
1191 .id = V4L2_CID_HUE,
1192 .value = 0x80,
1193 };
1194 static struct v4l2_control contrast = {
1195 .id = V4L2_CID_CONTRAST,
1196 .value = 0x80,
1197 };
1198 static struct v4l2_control brightness = {
1199 .id = V4L2_CID_BRIGHTNESS,
1200 .value = 0x80,
1201 };
1190 1202
1191 set_control(dev,&mute); 1203 set_control(dev,&mute);
1192 set_control(dev,&volume); 1204 set_control(dev,&volume);
1205 set_control(dev,&hue);
1206 set_control(dev,&contrast);
1207 set_control(dev,&brightness);
1193} 1208}
1194 1209
1195/* ------------------------------------------------------------------ */ 1210/* ------------------------------------------------------------------ */
@@ -1336,6 +1351,9 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1336 V4L2_CAP_STREAMING | 1351 V4L2_CAP_STREAMING |
1337 V4L2_CAP_VBI_CAPTURE | 1352 V4L2_CAP_VBI_CAPTURE |
1338#if 0 1353#if 0
1354 V4L2_TUNER_CAP_LOW |
1355#endif
1356#if 0
1339 V4L2_CAP_VIDEO_OVERLAY | 1357 V4L2_CAP_VIDEO_OVERLAY |
1340#endif 1358#endif
1341 0; 1359 0;
@@ -1696,7 +1714,11 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1696 sizeof(cap->card)); 1714 sizeof(cap->card));
1697 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci)); 1715 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1698 cap->version = CX88_VERSION_CODE; 1716 cap->version = CX88_VERSION_CODE;
1699 cap->capabilities = V4L2_CAP_TUNER; 1717 cap->capabilities = V4L2_CAP_TUNER
1718#if 0
1719 | V4L2_TUNER_CAP_LOW
1720#endif
1721 ;
1700 return 0; 1722 return 0;
1701 } 1723 }
1702 case VIDIOC_G_TUNER: 1724 case VIDIOC_G_TUNER:
@@ -1992,6 +2014,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1992{ 2014{
1993 struct cx8800_dev *dev; 2015 struct cx8800_dev *dev;
1994 struct cx88_core *core; 2016 struct cx88_core *core;
2017 struct tuner_addr tun_addr;
1995 int err; 2018 int err;
1996 2019
1997 dev = kmalloc(sizeof(*dev),GFP_KERNEL); 2020 dev = kmalloc(sizeof(*dev),GFP_KERNEL);
@@ -2065,8 +2088,19 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
2065 request_module("tuner"); 2088 request_module("tuner");
2066 if (core->tda9887_conf) 2089 if (core->tda9887_conf)
2067 request_module("tda9887"); 2090 request_module("tda9887");
2068 if (core->tuner_type != UNSET) 2091 if (core->radio_type != UNSET) {
2069 cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE,&core->tuner_type); 2092 tun_addr.v4l2_tuner = V4L2_TUNER_RADIO;
2093 tun_addr.type = core->radio_type;
2094 tun_addr.addr = core->radio_addr;
2095 cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE_ADDR, &tun_addr);
2096 }
2097 if (core->tuner_type != UNSET) {
2098 tun_addr.v4l2_tuner = V4L2_TUNER_ANALOG_TV;
2099 tun_addr.type = core->tuner_type;
2100 tun_addr.addr = core->tuner_addr;
2101 cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE_ADDR, &tun_addr);
2102 }
2103
2070 if (core->tda9887_conf) 2104 if (core->tda9887_conf)
2071 cx88_call_i2c_clients(dev->core,TDA9887_SET_CONFIG,&core->tda9887_conf); 2105 cx88_call_i2c_clients(dev->core,TDA9887_SET_CONFIG,&core->tda9887_conf);
2072 2106
@@ -2162,7 +2196,7 @@ static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
2162 2196
2163static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state) 2197static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2164{ 2198{
2165 struct cx8800_dev *dev = pci_get_drvdata(pci_dev); 2199 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
2166 struct cx88_core *core = dev->core; 2200 struct cx88_core *core = dev->core;
2167 2201
2168 /* stop video+vbi capture */ 2202 /* stop video+vbi capture */
@@ -2194,7 +2228,7 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2194 2228
2195static int cx8800_resume(struct pci_dev *pci_dev) 2229static int cx8800_resume(struct pci_dev *pci_dev)
2196{ 2230{
2197 struct cx8800_dev *dev = pci_get_drvdata(pci_dev); 2231 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
2198 struct cx88_core *core = dev->core; 2232 struct cx88_core *core = dev->core;
2199 2233
2200 if (dev->state.disabled) { 2234 if (dev->state.disabled) {
@@ -2230,8 +2264,8 @@ static struct pci_device_id cx8800_pci_tbl[] = {
2230 { 2264 {
2231 .vendor = 0x14f1, 2265 .vendor = 0x14f1,
2232 .device = 0x8800, 2266 .device = 0x8800,
2233 .subvendor = PCI_ANY_ID, 2267 .subvendor = PCI_ANY_ID,
2234 .subdevice = PCI_ANY_ID, 2268 .subdevice = PCI_ANY_ID,
2235 },{ 2269 },{
2236 /* --- end of list --- */ 2270 /* --- end of list --- */
2237 } 2271 }
@@ -2239,10 +2273,10 @@ static struct pci_device_id cx8800_pci_tbl[] = {
2239MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl); 2273MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
2240 2274
2241static struct pci_driver cx8800_pci_driver = { 2275static struct pci_driver cx8800_pci_driver = {
2242 .name = "cx8800", 2276 .name = "cx8800",
2243 .id_table = cx8800_pci_tbl, 2277 .id_table = cx8800_pci_tbl,
2244 .probe = cx8800_initdev, 2278 .probe = cx8800_initdev,
2245 .remove = __devexit_p(cx8800_finidev), 2279 .remove = __devexit_p(cx8800_finidev),
2246 2280
2247 .suspend = cx8800_suspend, 2281 .suspend = cx8800_suspend,
2248 .resume = cx8800_resume, 2282 .resume = cx8800_resume,
@@ -2274,4 +2308,5 @@ module_exit(cx8800_fini);
2274 * Local variables: 2308 * Local variables:
2275 * c-basic-offset: 8 2309 * c-basic-offset: 8
2276 * End: 2310 * End:
2311 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
2277 */ 2312 */
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 88eaaaba5ad8..867e988a5a93 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88.h,v 1.56 2005/03/04 09:12:23 kraxel Exp $ 2 * $Id: cx88.h,v 1.62 2005/06/12 04:19:19 mchehab Exp $
3 * 3 *
4 * v4l2 device driver for cx2388x based TV cards 4 * v4l2 device driver for cx2388x based TV cards
5 * 5 *
@@ -64,6 +64,13 @@
64#define SHADOW_AUD_BAL_CTL 2 64#define SHADOW_AUD_BAL_CTL 2
65#define SHADOW_MAX 2 65#define SHADOW_MAX 2
66 66
67/* FM Radio deemphasis type */
68enum cx88_deemph_type {
69 FM_NO_DEEMPH = 0,
70 FM_DEEMPH_50,
71 FM_DEEMPH_75
72};
73
67/* ----------------------------------------------------------- */ 74/* ----------------------------------------------------------- */
68/* tv norms */ 75/* tv norms */
69 76
@@ -162,6 +169,8 @@ extern struct sram_channel cx88_sram_channels[];
162#define CX88_BOARD_HAUPPAUGE_ROSLYN 24 169#define CX88_BOARD_HAUPPAUGE_ROSLYN 24
163#define CX88_BOARD_DIGITALLOGIC_MEC 25 170#define CX88_BOARD_DIGITALLOGIC_MEC 25
164#define CX88_BOARD_IODATA_GVBCTV7E 26 171#define CX88_BOARD_IODATA_GVBCTV7E 26
172#define CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO 27
173#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T 28
165 174
166enum cx88_itype { 175enum cx88_itype {
167 CX88_VMUX_COMPOSITE1 = 1, 176 CX88_VMUX_COMPOSITE1 = 1,
@@ -185,6 +194,9 @@ struct cx88_input {
185struct cx88_board { 194struct cx88_board {
186 char *name; 195 char *name;
187 unsigned int tuner_type; 196 unsigned int tuner_type;
197 unsigned int radio_type;
198 unsigned char tuner_addr;
199 unsigned char radio_addr;
188 int tda9887_conf; 200 int tda9887_conf;
189 struct cx88_input input[8]; 201 struct cx88_input input[8];
190 struct cx88_input radio; 202 struct cx88_input radio;
@@ -255,6 +267,9 @@ struct cx88_core {
255 /* config info -- analog */ 267 /* config info -- analog */
256 unsigned int board; 268 unsigned int board;
257 unsigned int tuner_type; 269 unsigned int tuner_type;
270 unsigned int radio_type;
271 unsigned char tuner_addr;
272 unsigned char radio_addr;
258 unsigned int tda9887_conf; 273 unsigned int tda9887_conf;
259 unsigned int has_radio; 274 unsigned int has_radio;
260 275
@@ -471,6 +486,11 @@ extern void cx88_core_put(struct cx88_core *core,
471/* cx88-vbi.c */ 486/* cx88-vbi.c */
472 487
473void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f); 488void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f);
489/*
490int cx8800_start_vbi_dma(struct cx8800_dev *dev,
491 struct cx88_dmaqueue *q,
492 struct cx88_buffer *buf);
493*/
474int cx8800_stop_vbi_dma(struct cx8800_dev *dev); 494int cx8800_stop_vbi_dma(struct cx8800_dev *dev);
475int cx8800_restart_vbi_queue(struct cx8800_dev *dev, 495int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
476 struct cx88_dmaqueue *q); 496 struct cx88_dmaqueue *q);
diff --git a/drivers/media/video/ir-kbd-gpio.c b/drivers/media/video/ir-kbd-gpio.c
index ab6620de4b3b..a565823330aa 100644
--- a/drivers/media/video/ir-kbd-gpio.c
+++ b/drivers/media/video/ir-kbd-gpio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ir-kbd-gpio.c,v 1.12 2005/02/22 12:28:40 kraxel Exp $ 2 * $Id: ir-kbd-gpio.c,v 1.13 2005/05/15 19:01:26 mchehab Exp $
3 * 3 *
4 * Copyright (c) 2003 Gerd Knorr 4 * Copyright (c) 2003 Gerd Knorr
5 * Copyright (c) 2003 Pavel Machek 5 * Copyright (c) 2003 Pavel Machek
@@ -114,38 +114,6 @@ static IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
114 [ 0x3e ] = KEY_VOLUMEUP, // 'volume +' 114 [ 0x3e ] = KEY_VOLUMEUP, // 'volume +'
115}; 115};
116 116
117static IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
118 [ 2 ] = KEY_KP0,
119 [ 1 ] = KEY_KP1,
120 [ 11 ] = KEY_KP2,
121 [ 27 ] = KEY_KP3,
122 [ 5 ] = KEY_KP4,
123 [ 9 ] = KEY_KP5,
124 [ 21 ] = KEY_KP6,
125 [ 6 ] = KEY_KP7,
126 [ 10 ] = KEY_KP8,
127 [ 18 ] = KEY_KP9,
128
129 [ 3 ] = KEY_TUNER, // TV/FM
130 [ 7 ] = KEY_SEARCH, // scan
131 [ 28 ] = KEY_ZOOM, // full screen
132 [ 30 ] = KEY_POWER,
133 [ 23 ] = KEY_VOLUMEDOWN,
134 [ 31 ] = KEY_VOLUMEUP,
135 [ 20 ] = KEY_CHANNELDOWN,
136 [ 22 ] = KEY_CHANNELUP,
137 [ 24 ] = KEY_MUTE,
138
139 [ 0 ] = KEY_LIST, // source
140 [ 19 ] = KEY_INFO, // loop
141 [ 16 ] = KEY_LAST, // +100
142 [ 13 ] = KEY_CLEAR, // reset
143 [ 12 ] = BTN_RIGHT, // fun++
144 [ 4 ] = BTN_LEFT, // fun--
145 [ 14 ] = KEY_GOTO, // function
146 [ 15 ] = KEY_STOP, // freeze
147};
148
149/* Attila Kondoros <attila.kondoros@chello.hu> */ 117/* Attila Kondoros <attila.kondoros@chello.hu> */
150static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = { 118static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
151 119
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index 7fbb8581a87d..b4ee9dfe6d42 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -147,7 +147,6 @@ static unsigned short normal_i2c[] = {
147 I2C_MSP3400C_ALT >> 1, 147 I2C_MSP3400C_ALT >> 1,
148 I2C_CLIENT_END 148 I2C_CLIENT_END
149}; 149};
150static unsigned short normal_i2c_range[] = {I2C_CLIENT_END,I2C_CLIENT_END};
151I2C_CLIENT_INSMOD; 150I2C_CLIENT_INSMOD;
152 151
153/* ----------------------------------------------------------------------- */ 152/* ----------------------------------------------------------------------- */
@@ -736,7 +735,6 @@ static int msp34xx_sleep(struct msp3400c *msp, int timeout)
736{ 735{
737 DECLARE_WAITQUEUE(wait, current); 736 DECLARE_WAITQUEUE(wait, current);
738 737
739again:
740 add_wait_queue(&msp->wq, &wait); 738 add_wait_queue(&msp->wq, &wait);
741 if (!kthread_should_stop()) { 739 if (!kthread_should_stop()) {
742 if (timeout < 0) { 740 if (timeout < 0) {
@@ -752,12 +750,8 @@ again:
752#endif 750#endif
753 } 751 }
754 } 752 }
755 753 try_to_freeze();
756 remove_wait_queue(&msp->wq, &wait); 754 remove_wait_queue(&msp->wq, &wait);
757
758 if (try_to_freeze(PF_FREEZE))
759 goto again;
760
761 return msp->restart; 755 return msp->restart;
762} 756}
763 757
@@ -1437,7 +1431,7 @@ static int msp_detach(struct i2c_client *client);
1437static int msp_probe(struct i2c_adapter *adap); 1431static int msp_probe(struct i2c_adapter *adap);
1438static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg); 1432static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
1439 1433
1440static int msp_suspend(struct device * dev, pm_message_t state, u32 level); 1434static int msp_suspend(struct device * dev, u32 state, u32 level);
1441static int msp_resume(struct device * dev, u32 level); 1435static int msp_resume(struct device * dev, u32 level);
1442 1436
1443static void msp_wake_thread(struct i2c_client *client); 1437static void msp_wake_thread(struct i2c_client *client);
@@ -1842,7 +1836,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
1842 return 0; 1836 return 0;
1843} 1837}
1844 1838
1845static int msp_suspend(struct device * dev, pm_message_t state, u32 level) 1839static int msp_suspend(struct device * dev, u32 state, u32 level)
1846{ 1840{
1847 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 1841 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
1848 1842
diff --git a/drivers/media/video/msp3400.h b/drivers/media/video/msp3400.h
index d70a954e13aa..023f33056a4f 100644
--- a/drivers/media/video/msp3400.h
+++ b/drivers/media/video/msp3400.h
@@ -1,3 +1,7 @@
1/*
2 * $Id: msp3400.h,v 1.3 2005/06/12 04:19:19 mchehab Exp $
3 */
4
1#ifndef MSP3400_H 5#ifndef MSP3400_H
2#define MSP3400_H 6#define MSP3400_H
3 7
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index ba69f09cbdd1..b8054da31ffd 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -64,7 +64,6 @@ static struct video_device saa_template; /* Declared near bottom */
64 64
65/* Addresses to scan */ 65/* Addresses to scan */
66static unsigned short normal_i2c[] = { I2C_ADDRESS, I2C_CLIENT_END }; 66static unsigned short normal_i2c[] = { I2C_ADDRESS, I2C_CLIENT_END };
67static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
68I2C_CLIENT_INSMOD; 67I2C_CLIENT_INSMOD;
69 68
70static struct i2c_client client_template; 69static struct i2c_client client_template;
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index d74caa139f0a..7ffa2e9a9bf3 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -132,7 +132,6 @@ static struct video_device saa_template; /* Declared near bottom */
132 132
133/* Addresses to scan */ 133/* Addresses to scan */
134static unsigned short normal_i2c[] = {34>>1,I2C_CLIENT_END}; 134static unsigned short normal_i2c[] = {34>>1,I2C_CLIENT_END};
135static unsigned short normal_i2c_range[] = {I2C_CLIENT_END};
136I2C_CLIENT_INSMOD; 135I2C_CLIENT_INSMOD;
137 136
138static struct i2c_client client_template; 137static struct i2c_client client_template;
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index 64273b438530..22d055d8a695 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -463,22 +463,14 @@ static unsigned short normal_i2c[] = {
463 (I2C_SAA7110 >> 1) + 1, 463 (I2C_SAA7110 >> 1) + 1,
464 I2C_CLIENT_END 464 I2C_CLIENT_END
465}; 465};
466static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
467 466
468static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 467static unsigned short ignore = I2C_CLIENT_END;
469static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
470static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
471static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
472static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
473 468
474static struct i2c_client_address_data addr_data = { 469static struct i2c_client_address_data addr_data = {
475 .normal_i2c = normal_i2c, 470 .normal_i2c = normal_i2c,
476 .normal_i2c_range = normal_i2c_range, 471 .probe = &ignore,
477 .probe = probe, 472 .ignore = &ignore,
478 .probe_range = probe_range, 473 .force = &ignore,
479 .ignore = ignore,
480 .ignore_range = ignore_range,
481 .force = force
482}; 474};
483 475
484static struct i2c_driver i2c_driver_saa7110; 476static struct i2c_driver i2c_driver_saa7110;
diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c
index 0a873112ae23..fcd897382fcf 100644
--- a/drivers/media/video/saa7111.c
+++ b/drivers/media/video/saa7111.c
@@ -482,22 +482,14 @@ saa7111_command (struct i2c_client *client,
482 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 482 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
483 */ 483 */
484static unsigned short normal_i2c[] = { I2C_SAA7111 >> 1, I2C_CLIENT_END }; 484static unsigned short normal_i2c[] = { I2C_SAA7111 >> 1, I2C_CLIENT_END };
485static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
486 485
487static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 486static unsigned short ignore = I2C_CLIENT_END;
488static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
489static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
490static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
491static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
492 487
493static struct i2c_client_address_data addr_data = { 488static struct i2c_client_address_data addr_data = {
494 .normal_i2c = normal_i2c, 489 .normal_i2c = normal_i2c,
495 .normal_i2c_range = normal_i2c_range, 490 .probe = &ignore,
496 .probe = probe, 491 .ignore = &ignore,
497 .probe_range = probe_range, 492 .force = &ignore,
498 .ignore = ignore,
499 .ignore_range = ignore_range,
500 .force = force
501}; 493};
502 494
503static struct i2c_driver i2c_driver_saa7111; 495static struct i2c_driver i2c_driver_saa7111;
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
index e73023695e58..2ba997f5ef1d 100644
--- a/drivers/media/video/saa7114.c
+++ b/drivers/media/video/saa7114.c
@@ -820,22 +820,14 @@ saa7114_command (struct i2c_client *client,
820 */ 820 */
821static unsigned short normal_i2c[] = 821static unsigned short normal_i2c[] =
822 { I2C_SAA7114 >> 1, I2C_SAA7114A >> 1, I2C_CLIENT_END }; 822 { I2C_SAA7114 >> 1, I2C_SAA7114A >> 1, I2C_CLIENT_END };
823static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
824 823
825static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 824static unsigned short ignore = I2C_CLIENT_END;
826static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
827static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
828static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
829static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
830 825
831static struct i2c_client_address_data addr_data = { 826static struct i2c_client_address_data addr_data = {
832 .normal_i2c = normal_i2c, 827 .normal_i2c = normal_i2c,
833 .normal_i2c_range = normal_i2c_range, 828 .probe = &ignore,
834 .probe = probe, 829 .ignore = &ignore,
835 .probe_range = probe_range, 830 .force = &ignore,
836 .ignore = ignore,
837 .ignore_range = ignore_range,
838 .force = force
839}; 831};
840 832
841static struct i2c_driver i2c_driver_saa7114; 833static struct i2c_driver i2c_driver_saa7114;
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index fe6abe34168c..e6d0a18833d6 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -22,7 +22,6 @@
22 22
23/* Addresses to scan */ 23/* Addresses to scan */
24static unsigned short normal_i2c[] = {0x20, I2C_CLIENT_END}; 24static unsigned short normal_i2c[] = {0x20, I2C_CLIENT_END};
25static unsigned short normal_i2c_range[] = {I2C_CLIENT_END};
26I2C_CLIENT_INSMOD; 25I2C_CLIENT_INSMOD;
27 26
28MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder"); 27MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder");
@@ -42,16 +41,16 @@ enum saa6752hs_videoformat {
42 41
43static const struct v4l2_format v4l2_format_table[] = 42static const struct v4l2_format v4l2_format_table[] =
44{ 43{
45 [SAA6752HS_VF_D1] = { 44 [SAA6752HS_VF_D1] =
46 .fmt.pix.width = 720, .fmt.pix.height = 576 }, 45 { .fmt = { .pix = { .width = 720, .height = 576 }}},
47 [SAA6752HS_VF_2_3_D1] = { 46 [SAA6752HS_VF_2_3_D1] =
48 .fmt.pix.width = 480, .fmt.pix.height = 576 }, 47 { .fmt = { .pix = { .width = 480, .height = 576 }}},
49 [SAA6752HS_VF_1_2_D1] = { 48 [SAA6752HS_VF_1_2_D1] =
50 .fmt.pix.width = 352, .fmt.pix.height = 576 }, 49 { .fmt = { .pix = { .width = 352, .height = 576 }}},
51 [SAA6752HS_VF_SIF] = { 50 [SAA6752HS_VF_SIF] =
52 .fmt.pix.width = 352, .fmt.pix.height = 288 }, 51 { .fmt = { .pix = { .width = 352, .height = 288 }}},
53 [SAA6752HS_VF_UNKNOWN] = { 52 [SAA6752HS_VF_UNKNOWN] =
54 .fmt.pix.width = 0, .fmt.pix.height = 0}, 53 { .fmt = { .pix = { .width = 0, .height = 0}}},
55}; 54};
56 55
57struct saa6752hs_state { 56struct saa6752hs_state {
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index c51eb7f078d3..0c781e24c446 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -1,6 +1,6 @@
1 1
2/* 2/*
3 * $Id: saa7134-cards.c,v 1.54 2005/03/07 12:01:51 kraxel Exp $ 3 * $Id: saa7134-cards.c,v 1.58 2005/06/07 18:05:00 nsh Exp $
4 * 4 *
5 * device driver for philips saa7134 based TV cards 5 * device driver for philips saa7134 based TV cards
6 * card-specific stuff. 6 * card-specific stuff.
@@ -165,7 +165,7 @@ struct saa7134_board saa7134_boards[] = {
165 .inputs = {{ 165 .inputs = {{
166 .name = name_tv, 166 .name = name_tv,
167 .vmux = 1, 167 .vmux = 1,
168 .amux = LINE2, 168 .amux = TV,
169 .tv = 1, 169 .tv = 1,
170 },{ 170 },{
171 .name = name_comp1, 171 .name = name_comp1,
@@ -878,7 +878,7 @@ struct saa7134_board saa7134_boards[] = {
878 }, 878 },
879 [SAA7134_BOARD_MANLI_MTV002] = { 879 [SAA7134_BOARD_MANLI_MTV002] = {
880 /* Ognjen Nastic <ognjen@logosoft.ba> */ 880 /* Ognjen Nastic <ognjen@logosoft.ba> */
881 .name = "Manli MuchTV M-TV002", 881 .name = "Manli MuchTV M-TV002/Behold TV 403 FM",
882 .audio_clock = 0x00200000, 882 .audio_clock = 0x00200000,
883 .tuner_type = TUNER_PHILIPS_PAL, 883 .tuner_type = TUNER_PHILIPS_PAL,
884 .inputs = {{ 884 .inputs = {{
@@ -899,14 +899,10 @@ struct saa7134_board saa7134_boards[] = {
899 .name = name_radio, 899 .name = name_radio,
900 .amux = LINE2, 900 .amux = LINE2,
901 }, 901 },
902 .mute = {
903 .name = name_mute,
904 .amux = LINE1,
905 },
906 }, 902 },
907 [SAA7134_BOARD_MANLI_MTV001] = { 903 [SAA7134_BOARD_MANLI_MTV001] = {
908 /* Ognjen Nastic <ognjen@logosoft.ba> UNTESTED */ 904 /* Ognjen Nastic <ognjen@logosoft.ba> UNTESTED */
909 .name = "Manli MuchTV M-TV001", 905 .name = "Manli MuchTV M-TV001/Behold TV 401",
910 .audio_clock = 0x00200000, 906 .audio_clock = 0x00200000,
911 .tuner_type = TUNER_PHILIPS_PAL, 907 .tuner_type = TUNER_PHILIPS_PAL,
912 .inputs = {{ 908 .inputs = {{
@@ -923,6 +919,10 @@ struct saa7134_board saa7134_boards[] = {
923 .amux = LINE2, 919 .amux = LINE2,
924 .tv = 1, 920 .tv = 1,
925 }}, 921 }},
922 .mute = {
923 .name = name_mute,
924 .amux = LINE1,
925 },
926 }, 926 },
927 [SAA7134_BOARD_TG3000TV] = { 927 [SAA7134_BOARD_TG3000TV] = {
928 /* TransGear 3000TV */ 928 /* TransGear 3000TV */
@@ -1078,7 +1078,6 @@ struct saa7134_board saa7134_boards[] = {
1078 .audio_clock = 0x00187de7, 1078 .audio_clock = 0x00187de7,
1079 .tuner_type = TUNER_PHILIPS_FM1256_IH3, 1079 .tuner_type = TUNER_PHILIPS_FM1256_IH3,
1080 .tda9887_conf = TDA9887_PRESENT, 1080 .tda9887_conf = TDA9887_PRESENT,
1081 .gpiomask = 0x3,
1082 .inputs = {{ 1081 .inputs = {{
1083 .name = name_tv, 1082 .name = name_tv,
1084 .vmux = 1, 1083 .vmux = 1,
@@ -1285,7 +1284,7 @@ struct saa7134_board saa7134_boards[] = {
1285 .gpio =0x8000, 1284 .gpio =0x8000,
1286 } 1285 }
1287 }, 1286 },
1288 [SAA7134_BOARD_AVERMEDIA_307] = { 1287 [SAA7134_BOARD_AVERMEDIA_STUDIO_307] = {
1289 /* 1288 /*
1290 Nickolay V. Shmyrev <nshmyrev@yandex.ru> 1289 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
1291 Lots of thanks to Andrey Zolotarev <zolotarev_andrey@mail.ru> 1290 Lots of thanks to Andrey Zolotarev <zolotarev_andrey@mail.ru>
@@ -1323,6 +1322,35 @@ struct saa7134_board saa7134_boards[] = {
1323 .gpio = 0x01, 1322 .gpio = 0x01,
1324 }, 1323 },
1325 }, 1324 },
1325 [SAA7134_BOARD_AVERMEDIA_GO_007_FM] = {
1326 .name = "Avermedia AVerTV GO 007 FM",
1327 .audio_clock = 0x00187de7,
1328 .tuner_type = TUNER_PHILIPS_TDA8290,
1329 .gpiomask = 0x00300003,
1330// .gpiomask = 0x8c240003,
1331 .inputs = {{
1332 .name = name_tv,
1333 .vmux = 1,
1334 .amux = TV,
1335 .tv = 1,
1336 .gpio = 0x01,
1337 },{
1338 .name = name_comp1,
1339 .vmux = 0,
1340 .amux = LINE2,
1341 .gpio = 0x02,
1342 },{
1343 .name = name_svideo,
1344 .vmux = 6,
1345 .amux = LINE2,
1346 .gpio = 0x02,
1347 }},
1348 .radio = {
1349 .name = name_radio,
1350 .amux = LINE1,
1351 .gpio = 0x00300001,
1352 },
1353 },
1326 [SAA7134_BOARD_AVERMEDIA_CARDBUS] = { 1354 [SAA7134_BOARD_AVERMEDIA_CARDBUS] = {
1327 /* Jon Westgate <oryn@oryn.fsck.tv> */ 1355 /* Jon Westgate <oryn@oryn.fsck.tv> */
1328 .name = "AVerMedia Cardbus TV/Radio", 1356 .name = "AVerMedia Cardbus TV/Radio",
@@ -1492,7 +1520,6 @@ struct saa7134_board saa7134_boards[] = {
1492 .audio_clock = 0x00187de7, 1520 .audio_clock = 0x00187de7,
1493 .tuner_type = TUNER_PHILIPS_FQ1216ME, 1521 .tuner_type = TUNER_PHILIPS_FQ1216ME,
1494 .tda9887_conf = TDA9887_PRESENT, 1522 .tda9887_conf = TDA9887_PRESENT,
1495 .gpiomask = 0x3,
1496 .inputs = {{ 1523 .inputs = {{
1497 .name = name_tv, 1524 .name = name_tv,
1498 .vmux = 1, 1525 .vmux = 1,
@@ -1546,7 +1573,82 @@ struct saa7134_board saa7134_boards[] = {
1546// .gpio = 0x4000, 1573// .gpio = 0x4000,
1547 }}, 1574 }},
1548 }, 1575 },
1549}; 1576 [SAA7134_BOARD_AVERMEDIA_307] = {
1577 /*
1578 Davydov Vladimir <vladimir@iqmedia.com>
1579 */
1580 .name = "Avermedia AVerTV 307",
1581 .audio_clock = 0x00187de7,
1582 .tuner_type = TUNER_PHILIPS_FQ1216ME,
1583 .tda9887_conf = TDA9887_PRESENT,
1584 .inputs = {{
1585 .name = name_tv,
1586 .vmux = 1,
1587 .amux = TV,
1588 .tv = 1,
1589 },{
1590 .name = name_comp1,
1591 .vmux = 0,
1592 .amux = LINE1,
1593 },{
1594 .name = name_comp2,
1595 .vmux = 3,
1596 .amux = LINE1,
1597 },{
1598 .name = name_svideo,
1599 .vmux = 8,
1600 .amux = LINE1,
1601 }},
1602 },
1603 [SAA7134_BOARD_ADS_INSTANT_TV] = {
1604 .name = "ADS Tech Instant TV (saa7135)",
1605 .audio_clock = 0x00187de7,
1606 .tuner_type = TUNER_PHILIPS_TDA8290,
1607 .inputs = {{
1608 .name = name_tv,
1609 .vmux = 1,
1610 .amux = TV,
1611 .tv = 1,
1612 },{
1613 .name = name_comp1,
1614 .vmux = 3,
1615 .amux = LINE2,
1616 },{
1617 .name = name_svideo,
1618 .vmux = 8,
1619 .amux = LINE2,
1620 }},
1621 },
1622 [SAA7134_BOARD_KWORLD_VSTREAM_XPERT] = {
1623 .name = "Kworld/Tevion V-Stream Xpert TV PVR7134",
1624 .audio_clock = 0x00187de7,
1625 .tuner_type = TUNER_PHILIPS_PAL_I,
1626 .gpiomask = 0x0700,
1627 .inputs = {{
1628 .name = name_tv,
1629 .vmux = 1,
1630 .amux = TV,
1631 .tv = 1,
1632 .gpio = 0x000,
1633 },{
1634 .name = name_comp1,
1635 .vmux = 3,
1636 .amux = LINE1,
1637 .gpio = 0x200, //gpio by DScaler
1638 },{
1639 .name = name_svideo,
1640 .vmux = 0,
1641 .amux = LINE1,
1642 .gpio = 0x200,
1643 }},
1644 .radio = {
1645 .name = name_radio,
1646 .amux = LINE1,
1647 .gpio = 0x100,
1648 },
1649 },
1650 };
1651
1550const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 1652const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
1551 1653
1552/* ------------------------------------------------------------------ */ 1654/* ------------------------------------------------------------------ */
@@ -1663,7 +1765,7 @@ struct pci_device_id saa7134_pci_tbl[] = {
1663 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134, 1765 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1664 },{ 1766 },{
1665 .vendor = PCI_VENDOR_ID_PHILIPS, 1767 .vendor = PCI_VENDOR_ID_PHILIPS,
1666 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 1768 .device = PCI_DEVICE_ID_PHILIPS_SAA7135,
1667 .subvendor = PCI_VENDOR_ID_ASUSTEK, 1769 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1668 .subdevice = 0x4845, 1770 .subdevice = 0x4845,
1669 .driver_data = SAA7135_BOARD_ASUSTeK_TVFM7135, 1771 .driver_data = SAA7135_BOARD_ASUSTeK_TVFM7135,
@@ -1824,6 +1926,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
1824 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 1926 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1825 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 1927 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1826 .subdevice = 0x9715, 1928 .subdevice = 0x9715,
1929 .driver_data = SAA7134_BOARD_AVERMEDIA_STUDIO_307,
1930 },{
1931 .vendor = PCI_VENDOR_ID_PHILIPS,
1932 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1933 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1934 .subdevice = 0xa70a,
1827 .driver_data = SAA7134_BOARD_AVERMEDIA_307, 1935 .driver_data = SAA7134_BOARD_AVERMEDIA_307,
1828 },{ 1936 },{
1829 .vendor = PCI_VENDOR_ID_PHILIPS, 1937 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -1844,6 +1952,26 @@ struct pci_device_id saa7134_pci_tbl[] = {
1844 .subvendor = 0x5168, 1952 .subvendor = 0x5168,
1845 .subdevice = 0x0306, 1953 .subdevice = 0x0306,
1846 .driver_data = SAA7134_BOARD_FLYDVBTDUO, 1954 .driver_data = SAA7134_BOARD_FLYDVBTDUO,
1955 },{
1956 .vendor = PCI_VENDOR_ID_PHILIPS,
1957 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1958 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1959 .subdevice = 0xf31f,
1960 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM,
1961
1962 },{
1963 .vendor = PCI_VENDOR_ID_PHILIPS,
1964 .device = PCI_DEVICE_ID_PHILIPS_SAA7135,
1965 .subvendor = 0x1421,
1966 .subdevice = 0x0350, /* PCI version */
1967 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV,
1968
1969 },{
1970 .vendor = PCI_VENDOR_ID_PHILIPS,
1971 .device = PCI_DEVICE_ID_PHILIPS_SAA7135,
1972 .subvendor = 0x1421,
1973 .subdevice = 0x0370, /* cardbus version */
1974 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV,
1847 1975
1848 },{ 1976 },{
1849 /* --- boards without eeprom + subsystem ID --- */ 1977 /* --- boards without eeprom + subsystem ID --- */
@@ -1954,20 +2082,23 @@ int saa7134_board_init1(struct saa7134_dev *dev)
1954 dev->has_remote = 1; 2082 dev->has_remote = 1;
1955 board_flyvideo(dev); 2083 board_flyvideo(dev);
1956 break; 2084 break;
1957 case SAA7134_BOARD_FLYTVPLATINUM_FM: 2085 case SAA7134_BOARD_FLYTVPLATINUM_FM:
1958 case SAA7134_BOARD_CINERGY400: 2086 case SAA7134_BOARD_CINERGY400:
1959 case SAA7134_BOARD_CINERGY600: 2087 case SAA7134_BOARD_CINERGY600:
1960 case SAA7134_BOARD_CINERGY600_MK3: 2088 case SAA7134_BOARD_CINERGY600_MK3:
1961 case SAA7134_BOARD_ECS_TVP3XP: 2089 case SAA7134_BOARD_ECS_TVP3XP:
1962 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 2090 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
1963 case SAA7134_BOARD_MD2819: 2091 case SAA7134_BOARD_MD2819:
2092 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
1964 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 2093 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
1965 case SAA7134_BOARD_AVERMEDIA_305: 2094 case SAA7134_BOARD_AVERMEDIA_305:
2095 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
1966 case SAA7134_BOARD_AVERMEDIA_307: 2096 case SAA7134_BOARD_AVERMEDIA_307:
2097 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
1967// case SAA7134_BOARD_SABRENT_SBTTVFM: /* not finished yet */ 2098// case SAA7134_BOARD_SABRENT_SBTTVFM: /* not finished yet */
1968 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 2099 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
1969 dev->has_remote = 1; 2100 case SAA7134_BOARD_MANLI_MTV001:
1970 break; 2101 case SAA7134_BOARD_MANLI_MTV002:
1971 case SAA7134_BOARD_AVACSSMARTTV: 2102 case SAA7134_BOARD_AVACSSMARTTV:
1972 dev->has_remote = 1; 2103 dev->has_remote = 1;
1973 break; 2104 break;
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index d506cafba8ff..f61ed1849a2a 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-core.c,v 1.28 2005/02/22 09:56:29 kraxel Exp $ 2 * $Id: saa7134-core.c,v 1.30 2005/05/22 19:23:39 nsh Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * driver core 5 * driver core
@@ -316,7 +316,7 @@ unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
316 316
317int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt) 317int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt)
318{ 318{
319 u32 *cpu; 319 __le32 *cpu;
320 dma_addr_t dma_addr; 320 dma_addr_t dma_addr;
321 321
322 cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr); 322 cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr);
@@ -332,7 +332,7 @@ int saa7134_pgtable_build(struct pci_dev *pci, struct saa7134_pgtable *pt,
332 struct scatterlist *list, unsigned int length, 332 struct scatterlist *list, unsigned int length,
333 unsigned int startpage) 333 unsigned int startpage)
334{ 334{
335 u32 *ptr; 335 __le32 *ptr;
336 unsigned int i,p; 336 unsigned int i,p;
337 337
338 BUG_ON(NULL == pt || NULL == pt->cpu); 338 BUG_ON(NULL == pt || NULL == pt->cpu);
@@ -340,7 +340,7 @@ int saa7134_pgtable_build(struct pci_dev *pci, struct saa7134_pgtable *pt,
340 ptr = pt->cpu + startpage; 340 ptr = pt->cpu + startpage;
341 for (i = 0; i < length; i++, list++) 341 for (i = 0; i < length; i++, list++)
342 for (p = 0; p * 4096 < list->length; p++, ptr++) 342 for (p = 0; p * 4096 < list->length; p++, ptr++)
343 *ptr = sg_dma_address(list) - list->offset; 343 *ptr = cpu_to_le32(sg_dma_address(list) - list->offset);
344 return 0; 344 return 0;
345} 345}
346 346
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index c2873ae029f9..aa8e2cf62d55 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-dvb.c,v 1.12 2005/02/18 12:28:29 kraxel Exp $ 2 * $Id: saa7134-dvb.c,v 1.13 2005/06/12 04:19:19 mchehab Exp $
3 * 3 *
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * 5 *
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index fa1357336907..c85348d0239f 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-empress.c,v 1.10 2005/02/03 10:24:33 kraxel Exp $ 2 * $Id: saa7134-empress.c,v 1.11 2005/05/22 19:23:39 nsh Exp $
3 * 3 *
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * 5 *
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 702bb63d9813..b6f002e8421d 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-i2c.c,v 1.10 2005/01/24 17:37:23 kraxel Exp $ 2 * $Id: saa7134-i2c.c,v 1.11 2005/06/12 01:36:14 mchehab Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * i2c interface support 5 * i2c interface support
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index ca50cf531f20..aba2b9de60de 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-input.c,v 1.16 2004/12/10 12:33:39 kraxel Exp $ 2 * $Id: saa7134-input.c,v 1.19 2005/06/07 18:02:26 nsh Exp $
3 * 3 *
4 * handle saa7134 IR remotes via linux kernel input layer. 4 * handle saa7134 IR remotes via linux kernel input layer.
5 * 5 *
@@ -308,6 +308,102 @@ static IR_KEYTAB_TYPE videomate_tv_pvr_codes[IR_KEYTAB_SIZE] = {
308 [ 32 ] = KEY_LANGUAGE, 308 [ 32 ] = KEY_LANGUAGE,
309 [ 33 ] = KEY_SLEEP, 309 [ 33 ] = KEY_SLEEP,
310}; 310};
311
312/* Michael Tokarev <mjt@tls.msk.ru>
313 http://www.corpit.ru/mjt/beholdTV/remote_control.jpg
314 keytable is used by MANLI MTV00[12] and BeholdTV 40[13] at
315 least, and probably other cards too.
316 The "ascii-art picture" below (in comments, first row
317 is the keycode in hex, and subsequent row(s) shows
318 the button labels (several variants when appropriate)
319 helps to descide which keycodes to assign to the buttons.
320 */
321static IR_KEYTAB_TYPE manli_codes[IR_KEYTAB_SIZE] = {
322
323 /* 0x1c 0x12 *
324 * FUNCTION POWER *
325 * FM (|) *
326 * */
327 [ 0x1c ] = KEY_RADIO, /*XXX*/
328 [ 0x12 ] = KEY_POWER,
329
330 /* 0x01 0x02 0x03 *
331 * 1 2 3 *
332 * *
333 * 0x04 0x05 0x06 *
334 * 4 5 6 *
335 * *
336 * 0x07 0x08 0x09 *
337 * 7 8 9 *
338 * */
339 [ 0x01 ] = KEY_KP1,
340 [ 0x02 ] = KEY_KP2,
341 [ 0x03 ] = KEY_KP3,
342 [ 0x04 ] = KEY_KP4,
343 [ 0x05 ] = KEY_KP5,
344 [ 0x06 ] = KEY_KP6,
345 [ 0x07 ] = KEY_KP7,
346 [ 0x08 ] = KEY_KP8,
347 [ 0x09 ] = KEY_KP9,
348
349 /* 0x0a 0x00 0x17 *
350 * RECALL 0 +100 *
351 * PLUS *
352 * */
353 [ 0x0a ] = KEY_AGAIN, /*XXX KEY_REWIND? */
354 [ 0x00 ] = KEY_KP0,
355 [ 0x17 ] = KEY_DIGITS, /*XXX*/
356
357 /* 0x14 0x10 *
358 * MENU INFO *
359 * OSD */
360 [ 0x14 ] = KEY_MENU,
361 [ 0x10 ] = KEY_INFO,
362
363 /* 0x0b *
364 * Up *
365 * *
366 * 0x18 0x16 0x0c *
367 * Left Ok Right *
368 * *
369 * 0x015 *
370 * Down *
371 * */
372 [ 0x0b ] = KEY_UP, /*XXX KEY_SCROLLUP? */
373 [ 0x18 ] = KEY_LEFT, /*XXX KEY_BACK? */
374 [ 0x16 ] = KEY_OK, /*XXX KEY_SELECT? KEY_ENTER? */
375 [ 0x0c ] = KEY_RIGHT, /*XXX KEY_FORWARD? */
376 [ 0x15 ] = KEY_DOWN, /*XXX KEY_SCROLLDOWN? */
377
378 /* 0x11 0x0d *
379 * TV/AV MODE *
380 * SOURCE STEREO *
381 * */
382 [ 0x11 ] = KEY_TV, /*XXX*/
383 [ 0x0d ] = KEY_MODE, /*XXX there's no KEY_STEREO */
384
385 /* 0x0f 0x1b 0x1a *
386 * AUDIO Vol+ Chan+ *
387 * TIMESHIFT??? *
388 * *
389 * 0x0e 0x1f 0x1e *
390 * SLEEP Vol- Chan- *
391 * */
392 [ 0x0f ] = KEY_AUDIO,
393 [ 0x1b ] = KEY_VOLUMEUP,
394 [ 0x1a ] = KEY_CHANNELUP,
395 [ 0x0e ] = KEY_SLEEP, /*XXX maybe KEY_PAUSE */
396 [ 0x1f ] = KEY_VOLUMEDOWN,
397 [ 0x1e ] = KEY_CHANNELDOWN,
398
399 /* 0x13 0x19 *
400 * MUTE SNAPSHOT*
401 * */
402 [ 0x13 ] = KEY_MUTE,
403 [ 0x19 ] = KEY_RECORD, /*XXX*/
404
405 // 0x1d unused ?
406};
311/* ---------------------------------------------------------------------- */ 407/* ---------------------------------------------------------------------- */
312 408
313static int build_key(struct saa7134_dev *dev) 409static int build_key(struct saa7134_dev *dev)
@@ -379,7 +475,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
379 switch (dev->board) { 475 switch (dev->board) {
380 case SAA7134_BOARD_FLYVIDEO2000: 476 case SAA7134_BOARD_FLYVIDEO2000:
381 case SAA7134_BOARD_FLYVIDEO3000: 477 case SAA7134_BOARD_FLYVIDEO3000:
382 case SAA7134_BOARD_FLYTVPLATINUM_FM: 478 case SAA7134_BOARD_FLYTVPLATINUM_FM:
383 ir_codes = flyvideo_codes; 479 ir_codes = flyvideo_codes;
384 mask_keycode = 0xEC00000; 480 mask_keycode = 0xEC00000;
385 mask_keydown = 0x0040000; 481 mask_keydown = 0x0040000;
@@ -405,8 +501,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
405 polling = 50; // ms 501 polling = 50; // ms
406 break; 502 break;
407 case SAA7134_BOARD_MD2819: 503 case SAA7134_BOARD_MD2819:
504 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
408 case SAA7134_BOARD_AVERMEDIA_305: 505 case SAA7134_BOARD_AVERMEDIA_305:
409 case SAA7134_BOARD_AVERMEDIA_307: 506 case SAA7134_BOARD_AVERMEDIA_307:
507 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
508 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
509 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
410 ir_codes = md2819_codes; 510 ir_codes = md2819_codes;
411 mask_keycode = 0x0007C8; 511 mask_keycode = 0x0007C8;
412 mask_keydown = 0x000010; 512 mask_keydown = 0x000010;
@@ -415,6 +515,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
415 saa_setb(SAA7134_GPIO_GPMODE0, 0x4); 515 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
416 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); 516 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
417 break; 517 break;
518 case SAA7134_BOARD_MANLI_MTV001:
519 case SAA7134_BOARD_MANLI_MTV002:
520 ir_codes = manli_codes;
521 mask_keycode = 0x001f00;
522 mask_keyup = 0x004000;
523 mask_keydown = 0x002000;
524 polling = 50; // ms
525 break;
418 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 526 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
419 ir_codes = videomate_tv_pvr_codes; 527 ir_codes = videomate_tv_pvr_codes;
420 mask_keycode = 0x00003F; 528 mask_keycode = 0x00003F;
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index 6b6a643bf1cd..81732904623f 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-oss.c,v 1.13 2004/12/10 12:33:39 kraxel Exp $ 2 * $Id: saa7134-oss.c,v 1.14 2005/05/18 22:45:16 hhackmann Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * oss dsp interface 5 * oss dsp interface
@@ -49,7 +49,6 @@ MODULE_PARM_DESC(oss_rate,"sample rate (valid are: 32000,48000)");
49 49
50static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks) 50static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks)
51{ 51{
52 blksize &= ~0xff;
53 if (blksize < 0x100) 52 if (blksize < 0x100)
54 blksize = 0x100; 53 blksize = 0x100;
55 if (blksize > 0x10000) 54 if (blksize > 0x10000)
@@ -57,8 +56,6 @@ static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks)
57 56
58 if (blocks < 2) 57 if (blocks < 2)
59 blocks = 2; 58 blocks = 2;
60 while ((blksize * blocks) & ~PAGE_MASK)
61 blocks++;
62 if ((blksize * blocks) > 1024*1024) 59 if ((blksize * blocks) > 1024*1024)
63 blocks = 1024*1024 / blksize; 60 blocks = 1024*1024 / blksize;
64 61
@@ -79,7 +76,7 @@ static int dsp_buffer_init(struct saa7134_dev *dev)
79 BUG(); 76 BUG();
80 videobuf_dma_init(&dev->oss.dma); 77 videobuf_dma_init(&dev->oss.dma);
81 err = videobuf_dma_init_kernel(&dev->oss.dma, PCI_DMA_FROMDEVICE, 78 err = videobuf_dma_init_kernel(&dev->oss.dma, PCI_DMA_FROMDEVICE,
82 dev->oss.bufsize >> PAGE_SHIFT); 79 (dev->oss.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
83 if (0 != err) 80 if (0 != err)
84 return err; 81 return err;
85 return 0; 82 return 0;
@@ -163,10 +160,11 @@ static int dsp_rec_start(struct saa7134_dev *dev)
163 fmt |= 0x04; 160 fmt |= 0x04;
164 fmt |= (TV == dev->oss.input) ? 0xc0 : 0x80; 161 fmt |= (TV == dev->oss.input) ? 0xc0 : 0x80;
165 162
166 saa_writeb(SAA7134_NUM_SAMPLES0, (dev->oss.blksize & 0x0000ff)); 163 saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->oss.blksize - 1) & 0x0000ff));
167 saa_writeb(SAA7134_NUM_SAMPLES1, (dev->oss.blksize & 0x00ff00) >> 8); 164 saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->oss.blksize - 1) & 0x00ff00) >> 8);
168 saa_writeb(SAA7134_NUM_SAMPLES2, (dev->oss.blksize & 0xff0000) >> 16); 165 saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->oss.blksize - 1) & 0xff0000) >> 16);
169 saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt); 166 saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt);
167
170 break; 168 break;
171 case PCI_DEVICE_ID_PHILIPS_SAA7133: 169 case PCI_DEVICE_ID_PHILIPS_SAA7133:
172 case PCI_DEVICE_ID_PHILIPS_SAA7135: 170 case PCI_DEVICE_ID_PHILIPS_SAA7135:
@@ -817,7 +815,7 @@ void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
817 reg = SAA7134_RS_BA1(6); 815 reg = SAA7134_RS_BA1(6);
818 } else { 816 } else {
819 /* even */ 817 /* even */
820 if (0 == (dev->oss.dma_blk & 0x00)) 818 if (1 == (dev->oss.dma_blk & 0x01))
821 reg = SAA7134_RS_BA2(6); 819 reg = SAA7134_RS_BA2(6);
822 } 820 }
823 if (0 == reg) { 821 if (0 == reg) {
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index ecac13c006d5..3617e7f7a410 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-tvaudio.c,v 1.22 2005/01/07 13:11:19 kraxel Exp $ 2 * $Id: saa7134-tvaudio.c,v 1.25 2005/06/07 19:00:38 nsh Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * tv audio decoder (fm stereo, nicam, ...) 5 * tv audio decoder (fm stereo, nicam, ...)
@@ -181,7 +181,8 @@ static void tvaudio_init(struct saa7134_dev *dev)
181 saa_writeb(SAA7134_AUDIO_CLOCK0, clock & 0xff); 181 saa_writeb(SAA7134_AUDIO_CLOCK0, clock & 0xff);
182 saa_writeb(SAA7134_AUDIO_CLOCK1, (clock >> 8) & 0xff); 182 saa_writeb(SAA7134_AUDIO_CLOCK1, (clock >> 8) & 0xff);
183 saa_writeb(SAA7134_AUDIO_CLOCK2, (clock >> 16) & 0xff); 183 saa_writeb(SAA7134_AUDIO_CLOCK2, (clock >> 16) & 0xff);
184 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x01); 184 // frame locked audio was reported not to be reliable
185 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x02);
185 186
186 saa_writeb(SAA7134_NICAM_ERROR_LOW, 0x14); 187 saa_writeb(SAA7134_NICAM_ERROR_LOW, 0x14);
187 saa_writeb(SAA7134_NICAM_ERROR_HIGH, 0x50); 188 saa_writeb(SAA7134_NICAM_ERROR_HIGH, 0x50);
@@ -250,6 +251,11 @@ static void mute_input_7134(struct saa7134_dev *dev)
250 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, ausel); 251 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, ausel);
251 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, ics); 252 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, ics);
252 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x07, ocs); 253 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x07, ocs);
254 // for oss, we need to change the clock configuration
255 if (in->amux == TV)
256 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
257 else
258 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x01);
253 259
254 /* switch gpio-connected external audio mux */ 260 /* switch gpio-connected external audio mux */
255 if (0 == card(dev).gpiomask) 261 if (0 == card(dev).gpiomask)
@@ -439,16 +445,15 @@ static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
439 nicam = saa_readb(SAA7134_NICAM_STATUS); 445 nicam = saa_readb(SAA7134_NICAM_STATUS);
440 dprintk("getstereo: nicam=0x%x\n",nicam); 446 dprintk("getstereo: nicam=0x%x\n",nicam);
441 switch (nicam & 0x0b) { 447 switch (nicam & 0x0b) {
448 case 0x08:
449 retval = V4L2_TUNER_SUB_MONO;
450 break;
442 case 0x09: 451 case 0x09:
443 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 452 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
444 break; 453 break;
445 case 0x0a: 454 case 0x0a:
446 retval = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; 455 retval = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
447 break; 456 break;
448 case 0x08:
449 default:
450 retval = V4L2_TUNER_SUB_MONO;
451 break;
452 } 457 }
453 break; 458 break;
454 } 459 }
@@ -572,14 +577,14 @@ static int tvaudio_thread(void *data)
572 } else if (0 != dev->last_carrier) { 577 } else if (0 != dev->last_carrier) {
573 /* no carrier -- try last detected one as fallback */ 578 /* no carrier -- try last detected one as fallback */
574 carrier = dev->last_carrier; 579 carrier = dev->last_carrier;
575 printk(KERN_WARNING "%s/audio: audio carrier scan failed, " 580 dprintk(KERN_WARNING "%s/audio: audio carrier scan failed, "
576 "using %d.%03d MHz [last detected]\n", 581 "using %d.%03d MHz [last detected]\n",
577 dev->name, carrier/1000, carrier%1000); 582 dev->name, carrier/1000, carrier%1000);
578 583
579 } else { 584 } else {
580 /* no carrier + no fallback -- use default */ 585 /* no carrier + no fallback -- use default */
581 carrier = default_carrier; 586 carrier = default_carrier;
582 printk(KERN_WARNING "%s/audio: audio carrier scan failed, " 587 dprintk(KERN_WARNING "%s/audio: audio carrier scan failed, "
583 "using %d.%03d MHz [default]\n", 588 "using %d.%03d MHz [default]\n",
584 dev->name, carrier/1000, carrier%1000); 589 dev->name, carrier/1000, carrier%1000);
585 } 590 }
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index 86954cc7c377..3c33c591cc85 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-vbi.c,v 1.6 2004/12/10 12:33:39 kraxel Exp $ 2 * $Id: saa7134-vbi.c,v 1.7 2005/05/24 23:13:06 nsh Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -60,10 +60,10 @@ static void task_init(struct saa7134_dev *dev, struct saa7134_buf *buf,
60 saa_writeb(SAA7134_VBI_H_START2(task), norm->h_start >> 8); 60 saa_writeb(SAA7134_VBI_H_START2(task), norm->h_start >> 8);
61 saa_writeb(SAA7134_VBI_H_STOP1(task), norm->h_stop & 0xff); 61 saa_writeb(SAA7134_VBI_H_STOP1(task), norm->h_stop & 0xff);
62 saa_writeb(SAA7134_VBI_H_STOP2(task), norm->h_stop >> 8); 62 saa_writeb(SAA7134_VBI_H_STOP2(task), norm->h_stop >> 8);
63 saa_writeb(SAA7134_VBI_V_START1(task), norm->vbi_v_start & 0xff); 63 saa_writeb(SAA7134_VBI_V_START1(task), norm->vbi_v_start_0 & 0xff);
64 saa_writeb(SAA7134_VBI_V_START2(task), norm->vbi_v_start >> 8); 64 saa_writeb(SAA7134_VBI_V_START2(task), norm->vbi_v_start_0 >> 8);
65 saa_writeb(SAA7134_VBI_V_STOP1(task), norm->vbi_v_stop & 0xff); 65 saa_writeb(SAA7134_VBI_V_STOP1(task), norm->vbi_v_stop_0 & 0xff);
66 saa_writeb(SAA7134_VBI_V_STOP2(task), norm->vbi_v_stop >> 8); 66 saa_writeb(SAA7134_VBI_V_STOP2(task), norm->vbi_v_stop_0 >> 8);
67 67
68 saa_writeb(SAA7134_VBI_H_SCALE_INC1(task), VBI_SCALE & 0xff); 68 saa_writeb(SAA7134_VBI_H_SCALE_INC1(task), VBI_SCALE & 0xff);
69 saa_writeb(SAA7134_VBI_H_SCALE_INC2(task), VBI_SCALE >> 8); 69 saa_writeb(SAA7134_VBI_H_SCALE_INC2(task), VBI_SCALE >> 8);
@@ -127,7 +127,7 @@ static int buffer_prepare(struct videobuf_queue *q,
127 unsigned int lines, llength, size; 127 unsigned int lines, llength, size;
128 int err; 128 int err;
129 129
130 lines = norm->vbi_v_stop - norm->vbi_v_start +1; 130 lines = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
131 if (lines > VBI_LINE_COUNT) 131 if (lines > VBI_LINE_COUNT)
132 lines = VBI_LINE_COUNT; 132 lines = VBI_LINE_COUNT;
133#if 1 133#if 1
@@ -177,7 +177,7 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
177 struct saa7134_dev *dev = fh->dev; 177 struct saa7134_dev *dev = fh->dev;
178 int llength,lines; 178 int llength,lines;
179 179
180 lines = dev->tvnorm->vbi_v_stop - dev->tvnorm->vbi_v_start +1; 180 lines = dev->tvnorm->vbi_v_stop_0 - dev->tvnorm->vbi_v_start_0 +1;
181#if 1 181#if 1
182 llength = VBI_LINE_LENGTH; 182 llength = VBI_LINE_LENGTH;
183#else 183#else
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 5d66060026ff..c0a2ee520531 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-video.c,v 1.28 2005/02/15 15:59:35 kraxel Exp $ 2 * $Id: saa7134-video.c,v 1.30 2005/06/07 19:00:38 nsh Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -31,8 +31,6 @@
31#include "saa7134-reg.h" 31#include "saa7134-reg.h"
32#include "saa7134.h" 32#include "saa7134.h"
33 33
34#define V4L2_I2C_CLIENTS 1
35
36/* ------------------------------------------------------------------ */ 34/* ------------------------------------------------------------------ */
37 35
38static unsigned int video_debug = 0; 36static unsigned int video_debug = 0;
@@ -158,18 +156,20 @@ static struct saa7134_format formats[] = {
158 .h_stop = 719, \ 156 .h_stop = 719, \
159 .video_v_start = 24, \ 157 .video_v_start = 24, \
160 .video_v_stop = 311, \ 158 .video_v_stop = 311, \
161 .vbi_v_start = 7, \ 159 .vbi_v_start_0 = 7, \
162 .vbi_v_stop = 22, \ 160 .vbi_v_stop_0 = 22, \
161 .vbi_v_start_1 = 319, \
163 .src_timing = 4 162 .src_timing = 4
164 163
165#define NORM_525_60 \ 164#define NORM_525_60 \
166 .h_start = 0, \ 165 .h_start = 0, \
167 .h_stop = 703, \ 166 .h_stop = 703, \
168 .video_v_start = 22, \ 167 .video_v_start = 23, \
169 .video_v_stop = 22+239, \ 168 .video_v_stop = 262, \
170 .vbi_v_start = 10, /* FIXME */ \ 169 .vbi_v_start_0 = 10, \
171 .vbi_v_stop = 21, /* FIXME */ \ 170 .vbi_v_stop_0 = 21, \
172 .src_timing = 1 171 .vbi_v_start_1 = 273, \
172 .src_timing = 7
173 173
174static struct saa7134_tvnorm tvnorms[] = { 174static struct saa7134_tvnorm tvnorms[] = {
175 { 175 {
@@ -274,11 +274,12 @@ static struct saa7134_tvnorm tvnorms[] = {
274 274
275 .h_start = 0, 275 .h_start = 0,
276 .h_stop = 719, 276 .h_stop = 719,
277 .video_v_start = 22, 277 .video_v_start = 23,
278 .video_v_stop = 22+239, 278 .video_v_stop = 262,
279 .vbi_v_start = 10, /* FIXME */ 279 .vbi_v_start_0 = 10,
280 .vbi_v_stop = 21, /* FIXME */ 280 .vbi_v_stop_0 = 21,
281 .src_timing = 1, 281 .vbi_v_start_1 = 273,
282 .src_timing = 7,
282 283
283 .sync_control = 0x18, 284 .sync_control = 0x18,
284 .luma_control = 0x40, 285 .luma_control = 0x40,
@@ -335,8 +336,8 @@ static const struct v4l2_queryctrl video_ctrls[] = {
335 .default_value = 0, 336 .default_value = 0,
336 .type = V4L2_CTRL_TYPE_INTEGER, 337 .type = V4L2_CTRL_TYPE_INTEGER,
337 },{ 338 },{
338 .id = V4L2_CID_VFLIP, 339 .id = V4L2_CID_HFLIP,
339 .name = "vertical flip", 340 .name = "Mirror",
340 .minimum = 0, 341 .minimum = 0,
341 .maximum = 1, 342 .maximum = 1,
342 .type = V4L2_CTRL_TYPE_BOOLEAN, 343 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -482,7 +483,7 @@ static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
482 dev->crop_bounds.width = norm->h_stop - norm->h_start +1; 483 dev->crop_bounds.width = norm->h_stop - norm->h_start +1;
483 dev->crop_defrect.width = norm->h_stop - norm->h_start +1; 484 dev->crop_defrect.width = norm->h_stop - norm->h_start +1;
484 485
485 dev->crop_bounds.top = (norm->vbi_v_stop+1)*2; 486 dev->crop_bounds.top = (norm->vbi_v_stop_0+1)*2;
486 dev->crop_defrect.top = norm->video_v_start*2; 487 dev->crop_defrect.top = norm->video_v_start*2;
487 dev->crop_bounds.height = ((norm->id & V4L2_STD_525_60) ? 524 : 624) 488 dev->crop_bounds.height = ((norm->id & V4L2_STD_525_60) ? 524 : 624)
488 - dev->crop_bounds.top; 489 - dev->crop_bounds.top;
@@ -521,22 +522,7 @@ static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
521 saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40); 522 saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40);
522 saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80); 523 saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80);
523 524
524#ifdef V4L2_I2C_CLIENTS
525 saa7134_i2c_call_clients(dev,VIDIOC_S_STD,&norm->id); 525 saa7134_i2c_call_clients(dev,VIDIOC_S_STD,&norm->id);
526#else
527 {
528 /* pass down info to the i2c chips (v4l1) */
529 struct video_channel c;
530 memset(&c,0,sizeof(c));
531 c.channel = dev->ctl_input;
532 c.norm = VIDEO_MODE_PAL;
533 if (norm->id & V4L2_STD_NTSC)
534 c.norm = VIDEO_MODE_NTSC;
535 if (norm->id & V4L2_STD_SECAM)
536 c.norm = VIDEO_MODE_SECAM;
537 saa7134_i2c_call_clients(dev,VIDIOCSCHAN,&c);
538 }
539#endif
540} 526}
541 527
542static void video_mux(struct saa7134_dev *dev, int input) 528static void video_mux(struct saa7134_dev *dev, int input)
@@ -1064,7 +1050,7 @@ static int get_control(struct saa7134_dev *dev, struct v4l2_control *c)
1064 case V4L2_CID_PRIVATE_INVERT: 1050 case V4L2_CID_PRIVATE_INVERT:
1065 c->value = dev->ctl_invert; 1051 c->value = dev->ctl_invert;
1066 break; 1052 break;
1067 case V4L2_CID_VFLIP: 1053 case V4L2_CID_HFLIP:
1068 c->value = dev->ctl_mirror; 1054 c->value = dev->ctl_mirror;
1069 break; 1055 break;
1070 case V4L2_CID_PRIVATE_Y_EVEN: 1056 case V4L2_CID_PRIVATE_Y_EVEN:
@@ -1139,7 +1125,7 @@ static int set_control(struct saa7134_dev *dev, struct saa7134_fh *fh,
1139 saa_writeb(SAA7134_DEC_CHROMA_SATURATION, 1125 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
1140 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation); 1126 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
1141 break; 1127 break;
1142 case V4L2_CID_VFLIP: 1128 case V4L2_CID_HFLIP:
1143 dev->ctl_mirror = c->value; 1129 dev->ctl_mirror = c->value;
1144 restart_overlay = 1; 1130 restart_overlay = 1;
1145 break; 1131 break;
@@ -1407,9 +1393,9 @@ static void saa7134_vbi_fmt(struct saa7134_dev *dev, struct v4l2_format *f)
1407 f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */; 1393 f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */;
1408 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 1394 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1409 f->fmt.vbi.offset = 64 * 4; 1395 f->fmt.vbi.offset = 64 * 4;
1410 f->fmt.vbi.start[0] = norm->vbi_v_start; 1396 f->fmt.vbi.start[0] = norm->vbi_v_start_0;
1411 f->fmt.vbi.count[0] = norm->vbi_v_stop - norm->vbi_v_start +1; 1397 f->fmt.vbi.count[0] = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
1412 f->fmt.vbi.start[1] = norm->video_v_stop + norm->vbi_v_start +1; 1398 f->fmt.vbi.start[1] = norm->vbi_v_start_1;
1413 f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; 1399 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1414 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */ 1400 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
1415 1401
@@ -1880,11 +1866,9 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1880 return -EINVAL; 1866 return -EINVAL;
1881 down(&dev->lock); 1867 down(&dev->lock);
1882 dev->ctl_freq = f->frequency; 1868 dev->ctl_freq = f->frequency;
1883#ifdef V4L2_I2C_CLIENTS 1869
1884 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,f); 1870 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,f);
1885#else 1871
1886 saa7134_i2c_call_clients(dev,VIDIOCSFREQ,&dev->ctl_freq);
1887#endif
1888 saa7134_tvaudio_do_scan(dev); 1872 saa7134_tvaudio_do_scan(dev);
1889 up(&dev->lock); 1873 up(&dev->lock);
1890 return 0; 1874 return 0;
@@ -2139,16 +2123,19 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
2139 t->rangelow = (int)(65*16); 2123 t->rangelow = (int)(65*16);
2140 t->rangehigh = (int)(108*16); 2124 t->rangehigh = (int)(108*16);
2141 2125
2142#ifdef V4L2_I2C_CLIENTS 2126 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
2143 saa7134_i2c_call_clients(dev,VIDIOC_G_TUNER,t); 2127
2144#else 2128 return 0;
2145 { 2129 }
2146 struct video_tuner vt; 2130 case VIDIOC_S_TUNER:
2147 memset(&vt,0,sizeof(vt)); 2131 {
2148 saa7134_i2c_call_clients(dev,VIDIOCGTUNER,&vt); 2132 struct v4l2_tuner *t = arg;
2149 t->signal = vt.signal; 2133
2150 } 2134 if (0 != t->index)
2151#endif 2135 return -EINVAL;
2136
2137 saa7134_i2c_call_clients(dev,VIDIOC_S_TUNER,t);
2138
2152 return 0; 2139 return 0;
2153 } 2140 }
2154 case VIDIOC_ENUMINPUT: 2141 case VIDIOC_ENUMINPUT:
@@ -2182,7 +2169,6 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
2182 return 0; 2169 return 0;
2183 } 2170 }
2184 case VIDIOC_S_AUDIO: 2171 case VIDIOC_S_AUDIO:
2185 case VIDIOC_S_TUNER:
2186 case VIDIOC_S_INPUT: 2172 case VIDIOC_S_INPUT:
2187 case VIDIOC_S_STD: 2173 case VIDIOC_S_STD:
2188 return 0; 2174 return 0;
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index ac90a9853236..d6b1c0d4d0f9 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134.h,v 1.38 2005/03/07 12:01:51 kraxel Exp $ 2 * $Id: saa7134.h,v 1.41 2005/06/07 18:02:26 nsh Exp $
3 * 3 *
4 * v4l2 device driver for philips saa7134 based TV cards 4 * v4l2 device driver for philips saa7134 based TV cards
5 * 5 *
@@ -21,7 +21,7 @@
21 */ 21 */
22 22
23#include <linux/version.h> 23#include <linux/version.h>
24#define SAA7134_VERSION_CODE KERNEL_VERSION(0,2,12) 24#define SAA7134_VERSION_CODE KERNEL_VERSION(0,2,13)
25 25
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
@@ -91,9 +91,10 @@ struct saa7134_tvnorm {
91 unsigned int h_stop; 91 unsigned int h_stop;
92 unsigned int video_v_start; 92 unsigned int video_v_start;
93 unsigned int video_v_stop; 93 unsigned int video_v_stop;
94 unsigned int vbi_v_start; 94 unsigned int vbi_v_start_0;
95 unsigned int vbi_v_stop; 95 unsigned int vbi_v_stop_0;
96 unsigned int src_timing; 96 unsigned int src_timing;
97 unsigned int vbi_v_start_1;
97}; 98};
98 99
99struct saa7134_tvaudio { 100struct saa7134_tvaudio {
@@ -167,7 +168,7 @@ struct saa7134_format {
167#define SAA7134_BOARD_SABRENT_SBTTVFM 42 168#define SAA7134_BOARD_SABRENT_SBTTVFM 42
168#define SAA7134_BOARD_ZOLID_XPERT_TV7134 43 169#define SAA7134_BOARD_ZOLID_XPERT_TV7134 43
169#define SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE 44 170#define SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE 44
170#define SAA7134_BOARD_AVERMEDIA_307 45 171#define SAA7134_BOARD_AVERMEDIA_STUDIO_307 45
171#define SAA7134_BOARD_AVERMEDIA_CARDBUS 46 172#define SAA7134_BOARD_AVERMEDIA_CARDBUS 46
172#define SAA7134_BOARD_CINERGY400_CARDBUS 47 173#define SAA7134_BOARD_CINERGY400_CARDBUS 47
173#define SAA7134_BOARD_CINERGY600_MK3 48 174#define SAA7134_BOARD_CINERGY600_MK3 48
@@ -178,6 +179,10 @@ struct saa7134_format {
178#define SAA7135_BOARD_ASUSTeK_TVFM7135 53 179#define SAA7135_BOARD_ASUSTeK_TVFM7135 53
179#define SAA7134_BOARD_FLYTVPLATINUM_FM 54 180#define SAA7134_BOARD_FLYTVPLATINUM_FM 54
180#define SAA7134_BOARD_FLYDVBTDUO 55 181#define SAA7134_BOARD_FLYDVBTDUO 55
182#define SAA7134_BOARD_AVERMEDIA_307 56
183#define SAA7134_BOARD_AVERMEDIA_GO_007_FM 57
184#define SAA7134_BOARD_ADS_INSTANT_TV 58
185#define SAA7134_BOARD_KWORLD_VSTREAM_XPERT 59
181 186
182#define SAA7134_MAXBOARDS 8 187#define SAA7134_MAXBOARDS 8
183#define SAA7134_INPUT_MAX 8 188#define SAA7134_INPUT_MAX 8
@@ -241,7 +246,7 @@ struct saa7134_dma;
241/* saa7134 page table */ 246/* saa7134 page table */
242struct saa7134_pgtable { 247struct saa7134_pgtable {
243 unsigned int size; 248 unsigned int size;
244 u32 *cpu; 249 __le32 *cpu;
245 dma_addr_t dma; 250 dma_addr_t dma;
246}; 251};
247 252
diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c
index 5f0b224c3cb6..108e7a4a0273 100644
--- a/drivers/media/video/saa7185.c
+++ b/drivers/media/video/saa7185.c
@@ -380,22 +380,14 @@ saa7185_command (struct i2c_client *client,
380 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 380 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
381 */ 381 */
382static unsigned short normal_i2c[] = { I2C_SAA7185 >> 1, I2C_CLIENT_END }; 382static unsigned short normal_i2c[] = { I2C_SAA7185 >> 1, I2C_CLIENT_END };
383static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
384 383
385static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 384static unsigned short ignore = I2C_CLIENT_END;
386static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
387static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
388static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
389static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
390 385
391static struct i2c_client_address_data addr_data = { 386static struct i2c_client_address_data addr_data = {
392 .normal_i2c = normal_i2c, 387 .normal_i2c = normal_i2c,
393 .normal_i2c_range = normal_i2c_range, 388 .probe = &ignore,
394 .probe = probe, 389 .ignore = &ignore,
395 .probe_range = probe_range, 390 .force = &ignore,
396 .ignore = ignore,
397 .ignore_range = ignore_range,
398 .force = force
399}; 391};
400 392
401static struct i2c_driver i2c_driver_saa7185; 393static struct i2c_driver i2c_driver_saa7185;
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index 376a4a439e9b..07ba6d3ed08c 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -74,7 +74,6 @@ static unsigned short normal_i2c[] = {
74 I2C_TDA7432 >> 1, 74 I2C_TDA7432 >> 1,
75 I2C_CLIENT_END, 75 I2C_CLIENT_END,
76}; 76};
77static unsigned short normal_i2c_range[] = { I2C_CLIENT_END, I2C_CLIENT_END };
78I2C_CLIENT_INSMOD; 77I2C_CLIENT_INSMOD;
79 78
80/* Structure of address and subaddresses for the tda7432 */ 79/* Structure of address and subaddresses for the tda7432 */
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index b5177c6f54f6..c29bdfc3244e 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -43,7 +43,6 @@ MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
43 43
44/* addresses to scan, found only at 0x42 (7-Bit) */ 44/* addresses to scan, found only at 0x42 (7-Bit) */
45static unsigned short normal_i2c[] = { I2C_TDA9840, I2C_CLIENT_END }; 45static unsigned short normal_i2c[] = { I2C_TDA9840, I2C_CLIENT_END };
46static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
47 46
48/* magic definition of all other variables and things */ 47/* magic definition of all other variables and things */
49I2C_CLIENT_INSMOD; 48I2C_CLIENT_INSMOD;
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index 4f1114c033a1..97b113e070f3 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -44,7 +44,6 @@ static unsigned short normal_i2c[] = {
44 I2C_TDA9875 >> 1, 44 I2C_TDA9875 >> 1,
45 I2C_CLIENT_END 45 I2C_CLIENT_END
46}; 46};
47static unsigned short normal_i2c_range[] = {I2C_CLIENT_END};
48I2C_CLIENT_INSMOD; 47I2C_CLIENT_INSMOD;
49 48
50/* This is a superset of the TDA9875 */ 49/* This is a superset of the TDA9875 */
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index debef1910c37..39773633cc3c 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -33,7 +33,6 @@ static unsigned short normal_i2c[] = {
33 0x96 >>1, 33 0x96 >>1,
34 I2C_CLIENT_END, 34 I2C_CLIENT_END,
35}; 35};
36static unsigned short normal_i2c_range[] = {I2C_CLIENT_END,I2C_CLIENT_END};
37I2C_CLIENT_INSMOD; 36I2C_CLIENT_INSMOD;
38 37
39/* insmod options */ 38/* insmod options */
@@ -54,6 +53,7 @@ struct tda9887 {
54 unsigned int config; 53 unsigned int config;
55 unsigned int pinnacle_id; 54 unsigned int pinnacle_id;
56 unsigned int using_v4l2; 55 unsigned int using_v4l2;
56 unsigned int radio_mode;
57}; 57};
58 58
59struct tvnorm { 59struct tvnorm {
@@ -213,12 +213,22 @@ static struct tvnorm tvnorms[] = {
213 } 213 }
214}; 214};
215 215
216static struct tvnorm radio = { 216static struct tvnorm radio_stereo = {
217 .name = "radio", 217 .name = "Radio Stereo",
218 .b = ( cFmRadio |
219 cQSS ),
220 .c = ( cDeemphasisOFF |
221 cAudioGain6 ),
222 .e = ( cAudioIF_5_5 |
223 cRadioIF_38_90 ),
224};
225
226static struct tvnorm radio_mono = {
227 .name = "Radio Mono",
218 .b = ( cFmRadio | 228 .b = ( cFmRadio |
219 cQSS ), 229 cQSS ),
220 .c = ( cDeemphasisON | 230 .c = ( cDeemphasisON |
221 cDeemphasis50 ), 231 cDeemphasis50),
222 .e = ( cAudioIF_5_5 | 232 .e = ( cAudioIF_5_5 |
223 cRadioIF_38_90 ), 233 cRadioIF_38_90 ),
224}; 234};
@@ -355,7 +365,10 @@ static int tda9887_set_tvnorm(struct tda9887 *t, char *buf)
355 int i; 365 int i;
356 366
357 if (t->radio) { 367 if (t->radio) {
358 norm = &radio; 368 if (t->radio_mode == V4L2_TUNER_MODE_MONO)
369 norm = &radio_mono;
370 else
371 norm = &radio_stereo;
359 } else { 372 } else {
360 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { 373 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) {
361 if (tvnorms[i].std & t->std) { 374 if (tvnorms[i].std & t->std) {
@@ -546,11 +559,14 @@ static int tda9887_configure(struct tda9887 *t)
546 559
547 memset(buf,0,sizeof(buf)); 560 memset(buf,0,sizeof(buf));
548 tda9887_set_tvnorm(t,buf); 561 tda9887_set_tvnorm(t,buf);
562
549 buf[1] |= cOutputPort1Inactive; 563 buf[1] |= cOutputPort1Inactive;
550 buf[1] |= cOutputPort2Inactive; 564 buf[1] |= cOutputPort2Inactive;
565
551 if (UNSET != t->pinnacle_id) { 566 if (UNSET != t->pinnacle_id) {
552 tda9887_set_pinnacle(t,buf); 567 tda9887_set_pinnacle(t,buf);
553 } 568 }
569
554 tda9887_set_config(t,buf); 570 tda9887_set_config(t,buf);
555 tda9887_set_insmod(t,buf); 571 tda9887_set_insmod(t,buf);
556 572
@@ -593,9 +609,12 @@ static int tda9887_attach(struct i2c_adapter *adap, int addr, int kind)
593 if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL))) 609 if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
594 return -ENOMEM; 610 return -ENOMEM;
595 memset(t,0,sizeof(*t)); 611 memset(t,0,sizeof(*t));
612
596 t->client = client_template; 613 t->client = client_template;
597 t->std = 0; 614 t->std = 0;
598 t->pinnacle_id = UNSET; 615 t->pinnacle_id = UNSET;
616 t->radio_mode = V4L2_TUNER_MODE_STEREO;
617
599 i2c_set_clientdata(&t->client, t); 618 i2c_set_clientdata(&t->client, t);
600 i2c_attach_client(&t->client); 619 i2c_attach_client(&t->client);
601 620
@@ -734,6 +753,16 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
734 } 753 }
735 break; 754 break;
736 } 755 }
756 case VIDIOC_S_TUNER:
757 {
758 struct v4l2_tuner* tuner = arg;
759
760 if (t->radio) {
761 t->radio_mode = tuner->audmode;
762 tda9887_configure (t);
763 }
764 break;
765 }
737 default: 766 default:
738 /* nothing */ 767 /* nothing */
739 break; 768 break;
@@ -741,7 +770,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
741 return 0; 770 return 0;
742} 771}
743 772
744static int tda9887_suspend(struct device * dev, pm_message_t state, u32 level) 773static int tda9887_suspend(struct device * dev, u32 state, u32 level)
745{ 774{
746 dprintk("tda9887: suspend\n"); 775 dprintk("tda9887: suspend\n");
747 return 0; 776 return 0;
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index 3ec39550bf46..b44db8a7b94d 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -43,7 +43,6 @@ MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
43 43
44/* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */ 44/* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */
45static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END }; 45static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END };
46static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
47 46
48/* magic definition of all other variables and things */ 47/* magic definition of all other variables and things */
49I2C_CLIENT_INSMOD; 48I2C_CLIENT_INSMOD;
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index bd10710fd909..48d4db7d507b 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -40,7 +40,6 @@ MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
40 40
41/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */ 41/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
42static unsigned short normal_i2c[] = { I2C_TEA6420_1, I2C_TEA6420_2, I2C_CLIENT_END }; 42static unsigned short normal_i2c[] = { I2C_TEA6420_1, I2C_TEA6420_2, I2C_CLIENT_END };
43static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
44 43
45/* magic definition of all other variables and things */ 44/* magic definition of all other variables and things */
46I2C_CLIENT_INSMOD; 45I2C_CLIENT_INSMOD;
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
index 6b20aa902a8f..51748c6578d1 100644
--- a/drivers/media/video/tuner-3036.c
+++ b/drivers/media/video/tuner-3036.c
@@ -34,19 +34,14 @@ static int this_adap;
34static struct i2c_client client_template; 34static struct i2c_client client_template;
35 35
36/* Addresses to scan */ 36/* Addresses to scan */
37static unsigned short normal_i2c[] = {I2C_CLIENT_END}; 37static unsigned short normal_i2c[] = { 0x60, 0x61, I2C_CLIENT_END };
38static unsigned short normal_i2c_range[] = {0x60, 0x61, I2C_CLIENT_END}; 38static unsigned short ignore = I2C_CLIENT_END;
39static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
40static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
41static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
42static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
43static unsigned short force[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
44 39
45static struct i2c_client_address_data addr_data = { 40static struct i2c_client_address_data addr_data = {
46 normal_i2c, normal_i2c_range, 41 .normal_i2c = normal_i2c,
47 probe, probe_range, 42 .probe = &ignore,
48 ignore, ignore_range, 43 .ignore = &ignore,
49 force 44 .force = &ignore,
50}; 45};
51 46
52/* ---------------------------------------------------------------------- */ 47/* ---------------------------------------------------------------------- */
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 6212388edb75..eaabfc858703 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-core.c,v 1.5 2005/02/15 15:59:35 kraxel Exp $ 2 * $Id: tuner-core.c,v 1.15 2005/06/12 01:36:14 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on 5 * core core, i.e. kernel interfaces, registering and so on
@@ -23,15 +23,18 @@
23#include <media/tuner.h> 23#include <media/tuner.h>
24#include <media/audiochip.h> 24#include <media/audiochip.h>
25 25
26/*
27 * comment line bellow to return to old behavor, where only one I2C device is supported
28 */
29#define CONFIG_TUNER_MULTI_I2C /**/
30
26#define UNSET (-1U) 31#define UNSET (-1U)
27 32
28/* standard i2c insmod options */ 33/* standard i2c insmod options */
29static unsigned short normal_i2c[] = { 34static unsigned short normal_i2c[] = {
30 0x4b, /* tda8290 */ 35 0x4b, /* tda8290 */
31 I2C_CLIENT_END 36 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
32}; 37 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
33static unsigned short normal_i2c_range[] = {
34 0x60, 0x6f,
35 I2C_CLIENT_END 38 I2C_CLIENT_END
36}; 39};
37I2C_CLIENT_INSMOD; 40I2C_CLIENT_INSMOD;
@@ -55,13 +58,16 @@ MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
55MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
56 59
57static int this_adap; 60static int this_adap;
61#ifdef CONFIG_TUNER_MULTI_I2C
62static unsigned short first_tuner, tv_tuner, radio_tuner;
63#endif
58 64
59static struct i2c_driver driver; 65static struct i2c_driver driver;
60static struct i2c_client client_template; 66static struct i2c_client client_template;
61 67
62/* ---------------------------------------------------------------------- */ 68/* ---------------------------------------------------------------------- */
63 69
64// Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz 70/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
65static void set_tv_freq(struct i2c_client *c, unsigned int freq) 71static void set_tv_freq(struct i2c_client *c, unsigned int freq)
66{ 72{
67 struct tuner *t = i2c_get_clientdata(c); 73 struct tuner *t = i2c_get_clientdata(c);
@@ -75,14 +81,26 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
75 return; 81 return;
76 } 82 }
77 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) { 83 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) {
78 /* FIXME: better do that chip-specific, but 84
79 right now we don't have that in the config 85 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) {
80 struct and this way is still better than no 86 /* V4L2_TUNER_CAP_LOW frequency */
81 check at all */ 87
82 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n", 88 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for TV. Tuners yet doesn't support converting it to valid freq.\n");
83 freq/16,freq%16*100/16,tv_range[0],tv_range[1]); 89
84 return; 90 t->tv_freq(c,freq>>10);
91
92 return;
93 } else {
94 /* FIXME: better do that chip-specific, but
95 right now we don't have that in the config
96 struct and this way is still better than no
97 check at all */
98 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n",
99 freq/16,freq%16*100/16,tv_range[0],tv_range[1]);
100 return;
101 }
85 } 102 }
103 tuner_dbg("62.5 Khz freq step selected for TV.\n");
86 t->tv_freq(c,freq); 104 t->tv_freq(c,freq);
87} 105}
88 106
@@ -99,11 +117,29 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
99 return; 117 return;
100 } 118 }
101 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) { 119 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) {
102 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n", 120 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) {
121 /* V4L2_TUNER_CAP_LOW frequency */
122 if (t->type == TUNER_TEA5767) {
123 tuner_info("radio freq step 62.5Hz (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
124 t->radio_freq(c,freq>>10);
125 return;
126 }
127
128 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for Radio. Tuners yet doesn't support converting it to valid freq.\n");
129
130 tuner_info("radio freq (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
131
132 t->radio_freq(c,freq>>10);
133 return;
134
135 } else {
136 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n",
103 freq/16,freq%16*100/16, 137 freq/16,freq%16*100/16,
104 radio_range[0],radio_range[1]); 138 radio_range[0],radio_range[1]);
105 return; 139 return;
140 }
106 } 141 }
142 tuner_dbg("62.5 Khz freq step selected for Radio.\n");
107 t->radio_freq(c,freq); 143 t->radio_freq(c,freq);
108} 144}
109 145
@@ -131,8 +167,9 @@ static void set_type(struct i2c_client *c, unsigned int type)
131{ 167{
132 struct tuner *t = i2c_get_clientdata(c); 168 struct tuner *t = i2c_get_clientdata(c);
133 169
170 tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type);
134 /* sanity check */ 171 /* sanity check */
135 if (type == UNSET || type == TUNER_ABSENT) 172 if (type == UNSET || type == TUNER_ABSENT)
136 return; 173 return;
137 if (type >= tuner_count) 174 if (type >= tuner_count)
138 return; 175 return;
@@ -147,6 +184,7 @@ static void set_type(struct i2c_client *c, unsigned int type)
147 return; 184 return;
148 185
149 t->initialized = 1; 186 t->initialized = 1;
187
150 t->type = type; 188 t->type = type;
151 switch (t->type) { 189 switch (t->type) {
152 case TUNER_MT2032: 190 case TUNER_MT2032:
@@ -161,6 +199,53 @@ static void set_type(struct i2c_client *c, unsigned int type)
161 } 199 }
162} 200}
163 201
202#ifdef CONFIG_TUNER_MULTI_I2C
203#define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \
204 return 0; } else \
205 tuner_info ("Cmd %s accepted to "tun"\n",cmd);
206#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \
207 CHECK_ADDR(radio_tuner,cmd,"radio") } else \
208 { CHECK_ADDR(tv_tuner,cmd,"TV"); }
209#else
210#define CHECK_ADDR(tp,cmd,tun) tuner_info ("Cmd %s accepted to "tun"\n",cmd);
211#define CHECK_MODE(cmd) tuner_info ("Cmd %s accepted\n",cmd);
212#endif
213
214#ifdef CONFIG_TUNER_MULTI_I2C
215
216static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr)
217{
218 /* ADDR_UNSET defaults to first available tuner */
219 if ( tun_addr->addr == ADDR_UNSET ) {
220 if (first_tuner != c->addr)
221 return;
222 switch (tun_addr->v4l2_tuner) {
223 case V4L2_TUNER_RADIO:
224 radio_tuner=c->addr;
225 break;
226 default:
227 tv_tuner=c->addr;
228 break;
229 }
230 } else {
231 /* Sets tuner to its configured value */
232 switch (tun_addr->v4l2_tuner) {
233 case V4L2_TUNER_RADIO:
234 radio_tuner=tun_addr->addr;
235 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
236 return;
237 default:
238 tv_tuner=tun_addr->addr;
239 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
240 return;
241 }
242 }
243 set_type(c,tun_addr->type);
244}
245#else
246#define set_addr(c,tun_addr) set_type(c,(tun_addr)->type)
247#endif
248
164static char pal[] = "-"; 249static char pal[] = "-";
165module_param_string(pal, pal, sizeof(pal), 0644); 250module_param_string(pal, pal, sizeof(pal), 0644);
166 251
@@ -199,8 +284,17 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
199{ 284{
200 struct tuner *t; 285 struct tuner *t;
201 286
287#ifndef CONFIG_TUNER_MULTI_I2C
202 if (this_adap > 0) 288 if (this_adap > 0)
203 return -1; 289 return -1;
290#else
291 /* by default, first I2C card is both tv and radio tuner */
292 if (this_adap == 0) {
293 first_tuner = addr;
294 tv_tuner = addr;
295 radio_tuner = addr;
296 }
297#endif
204 this_adap++; 298 this_adap++;
205 299
206 client_template.adapter = adap; 300 client_template.adapter = adap;
@@ -213,11 +307,12 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
213 memcpy(&t->i2c,&client_template,sizeof(struct i2c_client)); 307 memcpy(&t->i2c,&client_template,sizeof(struct i2c_client));
214 i2c_set_clientdata(&t->i2c, t); 308 i2c_set_clientdata(&t->i2c, t);
215 t->type = UNSET; 309 t->type = UNSET;
216 t->radio_if2 = 10700*1000; // 10.7MHz - FM radio 310 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */
217 311
218 i2c_attach_client(&t->i2c); 312 i2c_attach_client(&t->i2c);
219 tuner_info("chip found @ 0x%x (%s)\n", 313 tuner_info("chip found @ 0x%x (%s)\n",
220 addr << 1, adap->name); 314 addr << 1, adap->name);
315
221 set_type(&t->i2c, t->type); 316 set_type(&t->i2c, t->type);
222 return 0; 317 return 0;
223} 318}
@@ -225,12 +320,17 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
225static int tuner_probe(struct i2c_adapter *adap) 320static int tuner_probe(struct i2c_adapter *adap)
226{ 321{
227 if (0 != addr) { 322 if (0 != addr) {
228 normal_i2c[0] = addr; 323 normal_i2c[0] = addr;
229 normal_i2c_range[0] = addr; 324 normal_i2c[1] = I2C_CLIENT_END;
230 normal_i2c_range[1] = addr;
231 } 325 }
232 this_adap = 0; 326 this_adap = 0;
233 327
328#ifdef CONFIG_TUNER_MULTI_I2C
329 first_tuner = 0;
330 tv_tuner = 0;
331 radio_tuner = 0;
332#endif
333
234 if (adap->class & I2C_CLASS_TV_ANALOG) 334 if (adap->class & I2C_CLASS_TV_ANALOG)
235 return i2c_probe(adap, &addr_data, tuner_attach); 335 return i2c_probe(adap, &addr_data, tuner_attach);
236 return 0; 336 return 0;
@@ -239,8 +339,14 @@ static int tuner_probe(struct i2c_adapter *adap)
239static int tuner_detach(struct i2c_client *client) 339static int tuner_detach(struct i2c_client *client)
240{ 340{
241 struct tuner *t = i2c_get_clientdata(client); 341 struct tuner *t = i2c_get_clientdata(client);
342 int err;
343
344 err=i2c_detach_client(&t->i2c);
345 if (err) {
346 tuner_warn ("Client deregistration failed, client not detached.\n");
347 return err;
348 }
242 349
243 i2c_detach_client(&t->i2c);
244 kfree(t); 350 kfree(t);
245 return 0; 351 return 0;
246} 352}
@@ -259,18 +365,23 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
259 unsigned int *iarg = (int*)arg; 365 unsigned int *iarg = (int*)arg;
260 366
261 switch (cmd) { 367 switch (cmd) {
262
263 /* --- configuration --- */ 368 /* --- configuration --- */
264 case TUNER_SET_TYPE: 369 case TUNER_SET_TYPE:
265 set_type(client,*iarg); 370 set_type(client,*iarg);
266 break; 371 break;
372 case TUNER_SET_TYPE_ADDR:
373 set_addr(client,(struct tuner_addr *)arg);
374 break;
267 case AUDC_SET_RADIO: 375 case AUDC_SET_RADIO:
376 t->mode = V4L2_TUNER_RADIO;
377 CHECK_ADDR(tv_tuner,"AUDC_SET_RADIO","TV");
378
268 if (V4L2_TUNER_RADIO != t->mode) { 379 if (V4L2_TUNER_RADIO != t->mode) {
269 set_tv_freq(client,400 * 16); 380 set_tv_freq(client,400 * 16);
270 t->mode = V4L2_TUNER_RADIO;
271 } 381 }
272 break; 382 break;
273 case AUDC_CONFIG_PINNACLE: 383 case AUDC_CONFIG_PINNACLE:
384 CHECK_ADDR(tv_tuner,"AUDC_CONFIG_PINNACLE","TV");
274 switch (*iarg) { 385 switch (*iarg) {
275 case 2: 386 case 2:
276 tuner_dbg("pinnacle pal\n"); 387 tuner_dbg("pinnacle pal\n");
@@ -300,6 +411,8 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
300 411
301 CHECK_V4L2; 412 CHECK_V4L2;
302 t->mode = V4L2_TUNER_ANALOG_TV; 413 t->mode = V4L2_TUNER_ANALOG_TV;
414 CHECK_ADDR(tv_tuner,"VIDIOCSCHAN","TV");
415
303 if (vc->norm < ARRAY_SIZE(map)) 416 if (vc->norm < ARRAY_SIZE(map))
304 t->std = map[vc->norm]; 417 t->std = map[vc->norm];
305 tuner_fixup_std(t); 418 tuner_fixup_std(t);
@@ -311,6 +424,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
311 { 424 {
312 unsigned long *v = arg; 425 unsigned long *v = arg;
313 426
427 CHECK_MODE("VIDIOCSFREQ");
314 CHECK_V4L2; 428 CHECK_V4L2;
315 set_freq(client,*v); 429 set_freq(client,*v);
316 return 0; 430 return 0;
@@ -319,15 +433,27 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
319 { 433 {
320 struct video_tuner *vt = arg; 434 struct video_tuner *vt = arg;
321 435
436 CHECK_ADDR(radio_tuner,"VIDIOCGTUNER","radio");
322 CHECK_V4L2; 437 CHECK_V4L2;
323 if (V4L2_TUNER_RADIO == t->mode && t->has_signal) 438 if (V4L2_TUNER_RADIO == t->mode) {
324 vt->signal = t->has_signal(client); 439 if (t->has_signal)
440 vt->signal = t->has_signal(client);
441 if (t->is_stereo) {
442 if (t->is_stereo(client))
443 vt-> flags |= VIDEO_TUNER_STEREO_ON;
444 else
445 vt-> flags &= 0xffff ^ VIDEO_TUNER_STEREO_ON;
446 }
447 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */
448 }
449
325 return 0; 450 return 0;
326 } 451 }
327 case VIDIOCGAUDIO: 452 case VIDIOCGAUDIO:
328 { 453 {
329 struct video_audio *va = arg; 454 struct video_audio *va = arg;
330 455
456 CHECK_ADDR(radio_tuner,"VIDIOCGAUDIO","radio");
331 CHECK_V4L2; 457 CHECK_V4L2;
332 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo) 458 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo)
333 va->mode = t->is_stereo(client) 459 va->mode = t->is_stereo(client)
@@ -342,6 +468,8 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
342 468
343 SWITCH_V4L2; 469 SWITCH_V4L2;
344 t->mode = V4L2_TUNER_ANALOG_TV; 470 t->mode = V4L2_TUNER_ANALOG_TV;
471 CHECK_ADDR(tv_tuner,"VIDIOC_S_STD","TV");
472
345 t->std = *id; 473 t->std = *id;
346 tuner_fixup_std(t); 474 tuner_fixup_std(t);
347 if (t->freq) 475 if (t->freq)
@@ -352,6 +480,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
352 { 480 {
353 struct v4l2_frequency *f = arg; 481 struct v4l2_frequency *f = arg;
354 482
483 CHECK_MODE("VIDIOC_S_FREQUENCY");
355 SWITCH_V4L2; 484 SWITCH_V4L2;
356 if (V4L2_TUNER_RADIO == f->type && 485 if (V4L2_TUNER_RADIO == f->type &&
357 V4L2_TUNER_RADIO != t->mode) 486 V4L2_TUNER_RADIO != t->mode)
@@ -364,6 +493,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
364 { 493 {
365 struct v4l2_frequency *f = arg; 494 struct v4l2_frequency *f = arg;
366 495
496 CHECK_MODE("VIDIOC_G_FREQUENCY");
367 SWITCH_V4L2; 497 SWITCH_V4L2;
368 f->type = t->mode; 498 f->type = t->mode;
369 f->frequency = t->freq; 499 f->frequency = t->freq;
@@ -373,14 +503,29 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
373 { 503 {
374 struct v4l2_tuner *tuner = arg; 504 struct v4l2_tuner *tuner = arg;
375 505
506 CHECK_MODE("VIDIOC_G_TUNER");
376 SWITCH_V4L2; 507 SWITCH_V4L2;
377 if (V4L2_TUNER_RADIO == t->mode && t->has_signal) 508 if (V4L2_TUNER_RADIO == t->mode) {
378 tuner->signal = t->has_signal(client); 509 if (t->has_signal)
510 tuner -> signal = t->has_signal(client);
511 if (t->is_stereo) {
512 if (t->is_stereo(client)) {
513 tuner -> capability |= V4L2_TUNER_CAP_STEREO;
514 tuner -> rxsubchans |= V4L2_TUNER_SUB_STEREO;
515 } else {
516 tuner -> rxsubchans &= 0xffff ^ V4L2_TUNER_SUB_STEREO;
517 }
518 }
519 }
520 /* Wow to deal with V4L2_TUNER_CAP_LOW ? For now, it accepts from low at 62.5KHz step to high at 62.5 Hz */
379 tuner->rangelow = tv_range[0] * 16; 521 tuner->rangelow = tv_range[0] * 16;
380 tuner->rangehigh = tv_range[1] * 16; 522// tuner->rangehigh = tv_range[1] * 16;
523// tuner->rangelow = tv_range[0] * 16384;
524 tuner->rangehigh = tv_range[1] * 16384;
381 break; 525 break;
382 } 526 }
383 default: 527 default:
528 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd);
384 /* nothing */ 529 /* nothing */
385 break; 530 break;
386 } 531 }
@@ -388,7 +533,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
388 return 0; 533 return 0;
389} 534}
390 535
391static int tuner_suspend(struct device * dev, pm_message_t state, u32 level) 536static int tuner_suspend(struct device * dev, u32 state, u32 level)
392{ 537{
393 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 538 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
394 struct tuner *t = i2c_get_clientdata(c); 539 struct tuner *t = i2c_get_clientdata(c);
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 48c6ceff1dc2..539f30557317 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-simple.c,v 1.10 2005/03/08 08:38:00 kraxel Exp $ 2 * $Id: tuner-simple.c,v 1.21 2005/06/10 19:53:26 nsh Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls all those simple 4-control-bytes style tuners. 5 * controls all those simple 4-control-bytes style tuners.
@@ -212,7 +212,25 @@ static struct tunertype tuners[] = {
212 { "Philips FQ1236A MK4", Philips, NTSC, 212 { "Philips FQ1236A MK4", Philips, NTSC,
213 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 }, 213 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 },
214 214
215 /* Should work for TVF8531MF, TVF8831MF, TVF8731MF */
216 { "Ymec TVision TVF-8531MF", Philips, NTSC,
217 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732},
218 { "Ymec TVision TVF-5533MF", Philips, NTSC,
219 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732},
220
221 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC,
222 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732},
223 { "Tena TNF9533-D/IF", LGINNOTEK, PAL,
224 16*160.25, 16*464.25, 0x01,0x02,0x08,0x8e,623},
225
226 /*
227 * This entry is for TEA5767 FM radio only chip used on several boards
228 * w/TV tuner
229 */
230 { TEA5767_TUNER_NAME, Philips, RADIO,
231 -1, -1, 0, 0, 0, TEA5767_LOW_LO_32768,0},
215}; 232};
233
216unsigned const int tuner_count = ARRAY_SIZE(tuners); 234unsigned const int tuner_count = ARRAY_SIZE(tuners);
217 235
218/* ---------------------------------------------------------------------- */ 236/* ---------------------------------------------------------------------- */
@@ -223,6 +241,7 @@ static int tuner_getstatus(struct i2c_client *c)
223 241
224 if (1 != i2c_master_recv(c,&byte,1)) 242 if (1 != i2c_master_recv(c,&byte,1))
225 return 0; 243 return 0;
244
226 return byte; 245 return byte;
227} 246}
228 247
@@ -231,17 +250,33 @@ static int tuner_getstatus(struct i2c_client *c)
231#define TUNER_MODE 0x38 250#define TUNER_MODE 0x38
232#define TUNER_AFC 0x07 251#define TUNER_AFC 0x07
233 252
234#define TUNER_STEREO 0x10 /* radio mode */ 253#define TUNER_STEREO 0x10 /* radio mode */
235#define TUNER_SIGNAL 0x07 /* radio mode */ 254#define TUNER_STEREO_MK3 0x04 /* radio mode */
255#define TUNER_SIGNAL 0x07 /* radio mode */
236 256
237static int tuner_signal(struct i2c_client *c) 257static int tuner_signal(struct i2c_client *c)
238{ 258{
239 return (tuner_getstatus(c) & TUNER_SIGNAL)<<13; 259 return (tuner_getstatus(c) & TUNER_SIGNAL) << 13;
240} 260}
241 261
242static int tuner_stereo(struct i2c_client *c) 262static int tuner_stereo(struct i2c_client *c)
243{ 263{
244 return (tuner_getstatus (c) & TUNER_STEREO); 264 int stereo, status;
265 struct tuner *t = i2c_get_clientdata(c);
266
267 status = tuner_getstatus (c);
268
269 switch (t->type) {
270 case TUNER_PHILIPS_FM1216ME_MK3:
271 case TUNER_PHILIPS_FM1236_MK3:
272 case TUNER_PHILIPS_FM1256_IH3:
273 stereo = ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
274 break;
275 default:
276 stereo = status & TUNER_STEREO;
277 }
278
279 return stereo;
245} 280}
246 281
247#if 0 /* unused */ 282#if 0 /* unused */
@@ -424,6 +459,14 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
424 buffer[2] = tun->config; 459 buffer[2] = tun->config;
425 460
426 switch (t->type) { 461 switch (t->type) {
462 case TUNER_TENA_9533_DI:
463 case TUNER_YMEC_TVF_5533MF:
464
465 /*These values are empirically determinated */
466 div = (freq*122)/16 - 20;
467 buffer[2] = 0x88; /* could be also 0x80 */
468 buffer[3] = 0x19; /* could be also 0x10, 0x18, 0x99 */
469 break;
427 case TUNER_PHILIPS_FM1216ME_MK3: 470 case TUNER_PHILIPS_FM1216ME_MK3:
428 case TUNER_PHILIPS_FM1236_MK3: 471 case TUNER_PHILIPS_FM1236_MK3:
429 buffer[3] = 0x19; 472 buffer[3] = 0x19;
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 80dc34f18c2c..9a493bea76d8 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -148,7 +148,6 @@ static unsigned short normal_i2c[] = {
148 I2C_TDA9874 >> 1, 148 I2C_TDA9874 >> 1,
149 I2C_PIC16C54 >> 1, 149 I2C_PIC16C54 >> 1,
150 I2C_CLIENT_END }; 150 I2C_CLIENT_END };
151static unsigned short normal_i2c_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
152I2C_CLIENT_INSMOD; 151I2C_CLIENT_INSMOD;
153 152
154static struct i2c_driver driver; 153static struct i2c_driver driver;
@@ -286,7 +285,6 @@ static int chip_thread(void *data)
286 schedule(); 285 schedule();
287 } 286 }
288 remove_wait_queue(&chip->wq, &wait); 287 remove_wait_queue(&chip->wq, &wait);
289 try_to_freeze(PF_FREEZE);
290 if (chip->done || signal_pending(current)) 288 if (chip->done || signal_pending(current))
291 break; 289 break;
292 dprintk("%s: thread wakeup\n", i2c_clientname(&chip->c)); 290 dprintk("%s: thread wakeup\n", i2c_clientname(&chip->c));
@@ -1238,17 +1236,17 @@ static int ta8874z_checkit(struct CHIPSTATE *chip)
1238/* audio chip descriptions - struct CHIPDESC */ 1236/* audio chip descriptions - struct CHIPDESC */
1239 1237
1240/* insmod options to enable/disable individual audio chips */ 1238/* insmod options to enable/disable individual audio chips */
1241int tda8425 = 1; 1239static int tda8425 = 1;
1242int tda9840 = 1; 1240static int tda9840 = 1;
1243int tda9850 = 1; 1241static int tda9850 = 1;
1244int tda9855 = 1; 1242static int tda9855 = 1;
1245int tda9873 = 1; 1243static int tda9873 = 1;
1246int tda9874a = 1; 1244static int tda9874a = 1;
1247int tea6300 = 0; // address clash with msp34xx 1245static int tea6300 = 0; // address clash with msp34xx
1248int tea6320 = 0; // address clash with msp34xx 1246static int tea6320 = 0; // address clash with msp34xx
1249int tea6420 = 1; 1247static int tea6420 = 1;
1250int pic16c54 = 1; 1248static int pic16c54 = 1;
1251int ta8874z = 0; // address clash with tda9840 1249static int ta8874z = 0; // address clash with tda9840
1252 1250
1253module_param(tda8425, int, 0444); 1251module_param(tda8425, int, 0444);
1254module_param(tda9840, int, 0444); 1252module_param(tda9840, int, 0444);
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index e1443a0937e3..0f03c25489f1 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -75,7 +75,7 @@ hauppauge_tuner_fmt[] =
75 { 0x00000007, "PAL(B/G)" }, 75 { 0x00000007, "PAL(B/G)" },
76 { 0x00001000, "NTSC(M)" }, 76 { 0x00001000, "NTSC(M)" },
77 { 0x00000010, "PAL(I)" }, 77 { 0x00000010, "PAL(I)" },
78 { 0x00400000, "SECAM(L/L�)" }, 78 { 0x00400000, "SECAM(L/L´)" },
79 { 0x00000e00, "PAL(D/K)" }, 79 { 0x00000e00, "PAL(D/K)" },
80 { 0x03000000, "ATSC Digital" }, 80 { 0x03000000, "ATSC Digital" },
81}; 81};
@@ -482,7 +482,6 @@ static unsigned short normal_i2c[] = {
482 0xa0 >> 1, 482 0xa0 >> 1,
483 I2C_CLIENT_END, 483 I2C_CLIENT_END,
484}; 484};
485static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
486I2C_CLIENT_INSMOD; 485I2C_CLIENT_INSMOD;
487 486
488struct i2c_driver i2c_driver_tveeprom; 487struct i2c_driver i2c_driver_tveeprom;
diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c
index eafd7061b310..51b99cdbf29e 100644
--- a/drivers/media/video/tvmixer.c
+++ b/drivers/media/video/tvmixer.c
@@ -1,3 +1,7 @@
1/*
2 * $Id: tvmixer.c,v 1.8 2005/06/12 04:19:19 mchehab Exp $
3 */
4
1#include <linux/module.h> 5#include <linux/module.h>
2#include <linux/moduleparam.h> 6#include <linux/moduleparam.h>
3#include <linux/kernel.h> 7#include <linux/kernel.h>
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index b0d4bcb027d0..70ecbdb80277 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -1,4 +1,6 @@
1/* 1/*
2 * $Id: v4l1-compat.c,v 1.9 2005/06/12 04:19:19 mchehab Exp $
3 *
2 * Video for Linux Two 4 * Video for Linux Two
3 * Backward Compatibility Layer 5 * Backward Compatibility Layer
4 * 6 *
@@ -15,14 +17,11 @@
15 * 17 *
16 */ 18 */
17 19
18#ifndef __KERNEL__
19#define __KERNEL__
20#endif
21
22#include <linux/config.h> 20#include <linux/config.h>
23 21
24#include <linux/init.h> 22#include <linux/init.h>
25#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h>
26#include <linux/types.h> 25#include <linux/types.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/sched.h> 27#include <linux/sched.h>
@@ -787,12 +786,15 @@ v4l_compat_translate_ioctl(struct inode *inode,
787 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) 786 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
788 aud->step = qctrl2.step; 787 aud->step = qctrl2.step;
789 aud->mode = 0; 788 aud->mode = 0;
789
790 memset(&tun2,0,sizeof(tun2));
790 err = drv(inode, file, VIDIOC_G_TUNER, &tun2); 791 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
791 if (err < 0) { 792 if (err < 0) {
792 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err); 793 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err);
793 err = 0; 794 err = 0;
794 break; 795 break;
795 } 796 }
797
796 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2) 798 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
797 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 799 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
798 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO) 800 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
diff --git a/drivers/media/video/video-buf-dvb.c b/drivers/media/video/video-buf-dvb.c
index 31cc4ed9b747..15f5bb486963 100644
--- a/drivers/media/video/video-buf-dvb.c
+++ b/drivers/media/video/video-buf-dvb.c
@@ -62,8 +62,7 @@ static int videobuf_dvb_thread(void *data)
62 break; 62 break;
63 if (kthread_should_stop()) 63 if (kthread_should_stop())
64 break; 64 break;
65 if (current->flags & PF_FREEZE) 65 try_to_freeze();
66 refrigerator(PF_FREEZE);
67 66
68 /* feed buffer data to demux */ 67 /* feed buffer data to demux */
69 if (buf->state == STATE_DONE) 68 if (buf->state == STATE_DONE)
@@ -149,10 +148,10 @@ int videobuf_dvb_register(struct videobuf_dvb *dvb,
149 dvb->name, result); 148 dvb->name, result);
150 goto fail_adapter; 149 goto fail_adapter;
151 } 150 }
152 dvb->adapter->priv = adapter_priv; 151 dvb->adapter.priv = adapter_priv;
153 152
154 /* register frontend */ 153 /* register frontend */
155 result = dvb_register_frontend(dvb->adapter, dvb->frontend); 154 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
156 if (result < 0) { 155 if (result < 0) {
157 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", 156 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
158 dvb->name, result); 157 dvb->name, result);
@@ -178,7 +177,7 @@ int videobuf_dvb_register(struct videobuf_dvb *dvb,
178 dvb->dmxdev.filternum = 256; 177 dvb->dmxdev.filternum = 256;
179 dvb->dmxdev.demux = &dvb->demux.dmx; 178 dvb->dmxdev.demux = &dvb->demux.dmx;
180 dvb->dmxdev.capabilities = 0; 179 dvb->dmxdev.capabilities = 0;
181 result = dvb_dmxdev_init(&dvb->dmxdev, dvb->adapter); 180 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
182 if (result < 0) { 181 if (result < 0) {
183 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", 182 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
184 dvb->name, result); 183 dvb->name, result);
@@ -209,7 +208,7 @@ int videobuf_dvb_register(struct videobuf_dvb *dvb,
209 } 208 }
210 209
211 /* register network adapter */ 210 /* register network adapter */
212 dvb_net_init(dvb->adapter, &dvb->net, &dvb->demux.dmx); 211 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
213 return 0; 212 return 0;
214 213
215fail_fe_conn: 214fail_fe_conn:
@@ -223,7 +222,7 @@ fail_dmxdev:
223fail_dmx: 222fail_dmx:
224 dvb_unregister_frontend(dvb->frontend); 223 dvb_unregister_frontend(dvb->frontend);
225fail_frontend: 224fail_frontend:
226 dvb_unregister_adapter(dvb->adapter); 225 dvb_unregister_adapter(&dvb->adapter);
227fail_adapter: 226fail_adapter:
228 return result; 227 return result;
229} 228}
@@ -236,7 +235,7 @@ void videobuf_dvb_unregister(struct videobuf_dvb *dvb)
236 dvb_dmxdev_release(&dvb->dmxdev); 235 dvb_dmxdev_release(&dvb->dmxdev);
237 dvb_dmx_release(&dvb->demux); 236 dvb_dmx_release(&dvb->demux);
238 dvb_unregister_frontend(dvb->frontend); 237 dvb_unregister_frontend(dvb->frontend);
239 dvb_unregister_adapter(dvb->adapter); 238 dvb_unregister_adapter(&dvb->adapter);
240} 239}
241 240
242EXPORT_SYMBOL(videobuf_dvb_register); 241EXPORT_SYMBOL(videobuf_dvb_register);
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 0fd6c9a70917..5dbd9f6bf353 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -569,22 +569,14 @@ static unsigned short normal_i2c[] =
569 { I2C_VPX3220 >> 1, (I2C_VPX3220 >> 1) + 4, 569 { I2C_VPX3220 >> 1, (I2C_VPX3220 >> 1) + 4,
570 I2C_CLIENT_END 570 I2C_CLIENT_END
571}; 571};
572static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
573 572
574static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END }; 573static unsigned short ignore = I2C_CLIENT_END;
575static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
576static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
577static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
578static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
579 574
580static struct i2c_client_address_data addr_data = { 575static struct i2c_client_address_data addr_data = {
581 .normal_i2c = normal_i2c, 576 .normal_i2c = normal_i2c,
582 .normal_i2c_range = normal_i2c_range, 577 .probe = &ignore,
583 .probe = probe, 578 .ignore = &ignore,
584 .probe_range = probe_range, 579 .force = &ignore,
585 .ignore = ignore,
586 .ignore_range = ignore_range,
587 .force = force
588}; 580};
589 581
590static struct i2c_driver vpx3220_i2c_driver; 582static struct i2c_driver vpx3220_i2c_driver;