diff options
author | Akihiro Tsukada <tskd2@yahoo.co.jp> | 2009-08-25 01:39:51 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-09-18 23:51:48 -0400 |
commit | 5eca4823ea8f99a7109779f68cedb00535aa6834 (patch) | |
tree | b7edf65332d3d8ea48fce594580e10e188dbf612 /drivers | |
parent | 3d17fb1be937c8c025fc9f54b4e17e91081e7a4f (diff) |
V4L/DVB (13000): add driver for 774 Friio White USB ISDB-T receiver
This patch adds driver for 774 Friio White, ISDB-T USB receiver
Friio White is an USB 2.0 ISDB-T receiver. (http://www.friio.com/)
The device has a GL861 chip and a Comtech JDVBT90502 canned tuner module.
This driver ignores all the frontend_parameters except frequency,
as ISDB-T shares the same parameter configuration across the country
and thus the device can work like an intelligent one.
As this device does not include a CAM nor hardware descrambling feature,
the driver passes through scrambled TS streams.
There is Friio Black, a variant for ISDB-S, which shares the same USB
Vendor/Product ID with White, but it is not supported in this driver.
They should be identified in the initialization sequence,
but this feature is not tested.
Signed-off-by: Akihiro Tsukada <tskd2@yahoo.co.jp>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/dvb/dvb-usb/Kconfig | 6 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/Makefile | 3 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/dvb-usb-ids.h | 2 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/friio-fe.c | 483 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/friio.c | 525 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/friio.h | 99 |
6 files changed, 1118 insertions, 0 deletions
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig index c5ec9a5f3b3f..0e4b97fba384 100644 --- a/drivers/media/dvb/dvb-usb/Kconfig +++ b/drivers/media/dvb/dvb-usb/Kconfig | |||
@@ -316,3 +316,9 @@ config DVB_USB_CE6230 | |||
316 | select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE | 316 | select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE |
317 | help | 317 | help |
318 | Say Y here to support the Intel CE6230 DVB-T USB2.0 receiver | 318 | Say Y here to support the Intel CE6230 DVB-T USB2.0 receiver |
319 | |||
320 | config DVB_USB_FRIIO | ||
321 | tristate "Friio ISDB-T USB2.0 Receiver support" | ||
322 | depends on DVB_USB | ||
323 | help | ||
324 | Say Y here to support the Japanese DTV receiver Friio. | ||
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile index f92734ed777a..85b83a43d55d 100644 --- a/drivers/media/dvb/dvb-usb/Makefile +++ b/drivers/media/dvb/dvb-usb/Makefile | |||
@@ -79,6 +79,9 @@ obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o | |||
79 | dvb-usb-ce6230-objs = ce6230.o | 79 | dvb-usb-ce6230-objs = ce6230.o |
80 | obj-$(CONFIG_DVB_USB_CE6230) += dvb-usb-ce6230.o | 80 | obj-$(CONFIG_DVB_USB_CE6230) += dvb-usb-ce6230.o |
81 | 81 | ||
82 | dvb-usb-friio-objs = friio.o friio-fe.o | ||
83 | obj-$(CONFIG_DVB_USB_FRIIO) += dvb-usb-friio.o | ||
84 | |||
82 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ | 85 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ |
83 | # due to tuner-xc3028 | 86 | # due to tuner-xc3028 |
84 | EXTRA_CFLAGS += -Idrivers/media/common/tuners | 87 | EXTRA_CFLAGS += -Idrivers/media/common/tuners |
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h index 2d51e3c28207..a548c14c1944 100644 --- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h +++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h | |||
@@ -60,6 +60,7 @@ | |||
60 | #define USB_VID_YUAN 0x1164 | 60 | #define USB_VID_YUAN 0x1164 |
61 | #define USB_VID_XTENSIONS 0x1ae7 | 61 | #define USB_VID_XTENSIONS 0x1ae7 |
62 | #define USB_VID_HUMAX_COEX 0x10b9 | 62 | #define USB_VID_HUMAX_COEX 0x10b9 |
63 | #define USB_VID_774 0x7a69 | ||
63 | 64 | ||
64 | /* Product IDs */ | 65 | /* Product IDs */ |
65 | #define USB_PID_ADSTECH_USB2_COLD 0xa333 | 66 | #define USB_PID_ADSTECH_USB2_COLD 0xa333 |
@@ -274,5 +275,6 @@ | |||
274 | #define USB_PID_ELGATO_EYETV_DTT_Dlx 0x0020 | 275 | #define USB_PID_ELGATO_EYETV_DTT_Dlx 0x0020 |
275 | #define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD 0x5000 | 276 | #define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD 0x5000 |
276 | #define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_WARM 0x5001 | 277 | #define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_WARM 0x5001 |
278 | #define USB_PID_FRIIO_WHITE 0x0001 | ||
277 | 279 | ||
278 | #endif | 280 | #endif |
diff --git a/drivers/media/dvb/dvb-usb/friio-fe.c b/drivers/media/dvb/dvb-usb/friio-fe.c new file mode 100644 index 000000000000..c4dfe25cf60d --- /dev/null +++ b/drivers/media/dvb/dvb-usb/friio-fe.c | |||
@@ -0,0 +1,483 @@ | |||
1 | /* DVB USB compliant Linux driver for the Friio USB2.0 ISDB-T receiver. | ||
2 | * | ||
3 | * Copyright (C) 2009 Akihiro Tsukada <tskd2@yahoo.co.jp> | ||
4 | * | ||
5 | * This module is based off the the gl861 and vp702x modules. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the Free | ||
9 | * Software Foundation, version 2. | ||
10 | * | ||
11 | * see Documentation/dvb/README.dvb-usb for more information | ||
12 | */ | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/string.h> | ||
15 | #include <linux/slab.h> | ||
16 | |||
17 | #include "friio.h" | ||
18 | |||
19 | struct jdvbt90502_state { | ||
20 | struct i2c_adapter *i2c; | ||
21 | struct dvb_frontend frontend; | ||
22 | struct jdvbt90502_config config; | ||
23 | }; | ||
24 | |||
25 | /* NOTE: TC90502 has 16bit register-address? */ | ||
26 | /* register 0x0100 is used for reading PLL status, so reg is u16 here */ | ||
27 | static int jdvbt90502_reg_read(struct jdvbt90502_state *state, | ||
28 | const u16 reg, u8 *buf, const size_t count) | ||
29 | { | ||
30 | int ret; | ||
31 | u8 wbuf[3]; | ||
32 | struct i2c_msg msg[2]; | ||
33 | |||
34 | wbuf[0] = reg & 0xFF; | ||
35 | wbuf[1] = 0; | ||
36 | wbuf[2] = reg >> 8; | ||
37 | |||
38 | msg[0].addr = state->config.demod_address; | ||
39 | msg[0].flags = 0; | ||
40 | msg[0].buf = wbuf; | ||
41 | msg[0].len = sizeof(wbuf); | ||
42 | |||
43 | msg[1].addr = msg[0].addr; | ||
44 | msg[1].flags = I2C_M_RD; | ||
45 | msg[1].buf = buf; | ||
46 | msg[1].len = count; | ||
47 | |||
48 | ret = i2c_transfer(state->i2c, msg, 2); | ||
49 | if (ret != 2) { | ||
50 | deb_fe(" reg read failed.\n"); | ||
51 | return -EREMOTEIO; | ||
52 | } | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | /* currently 16bit register-address is not used, so reg is u8 here */ | ||
57 | static int jdvbt90502_single_reg_write(struct jdvbt90502_state *state, | ||
58 | const u8 reg, const u8 val) | ||
59 | { | ||
60 | struct i2c_msg msg; | ||
61 | u8 wbuf[2]; | ||
62 | |||
63 | wbuf[0] = reg; | ||
64 | wbuf[1] = val; | ||
65 | |||
66 | msg.addr = state->config.demod_address; | ||
67 | msg.flags = 0; | ||
68 | msg.buf = wbuf; | ||
69 | msg.len = sizeof(wbuf); | ||
70 | |||
71 | if (i2c_transfer(state->i2c, &msg, 1) != 1) { | ||
72 | deb_fe(" reg write failed."); | ||
73 | return -EREMOTEIO; | ||
74 | } | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static int _jdvbt90502_write(struct dvb_frontend *fe, u8 *buf, int len) | ||
79 | { | ||
80 | struct jdvbt90502_state *state = fe->demodulator_priv; | ||
81 | int err, i; | ||
82 | for (i = 0; i < len - 1; i++) { | ||
83 | err = jdvbt90502_single_reg_write(state, | ||
84 | buf[0] + i, buf[i + 1]); | ||
85 | if (err) | ||
86 | return err; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | /* read pll status byte via the demodulator's I2C register */ | ||
93 | /* note: Win box reads it by 8B block at the I2C addr 0x30 from reg:0x80 */ | ||
94 | static int jdvbt90502_pll_read(struct jdvbt90502_state *state, u8 *result) | ||
95 | { | ||
96 | int ret; | ||
97 | |||
98 | /* +1 for reading */ | ||
99 | u8 pll_addr_byte = (state->config.pll_address << 1) + 1; | ||
100 | |||
101 | *result = 0; | ||
102 | |||
103 | ret = jdvbt90502_single_reg_write(state, JDVBT90502_2ND_I2C_REG, | ||
104 | pll_addr_byte); | ||
105 | if (ret) | ||
106 | goto error; | ||
107 | |||
108 | ret = jdvbt90502_reg_read(state, 0x0100, result, 1); | ||
109 | if (ret) | ||
110 | goto error; | ||
111 | |||
112 | deb_fe("PLL read val:%02x\n", *result); | ||
113 | return 0; | ||
114 | |||
115 | error: | ||
116 | deb_fe("%s:ret == %d\n", __func__, ret); | ||
117 | return -EREMOTEIO; | ||
118 | } | ||
119 | |||
120 | |||
121 | /* set pll frequency via the demodulator's I2C register */ | ||
122 | static int jdvbt90502_pll_set_freq(struct jdvbt90502_state *state, u32 freq) | ||
123 | { | ||
124 | int ret; | ||
125 | int retry; | ||
126 | u8 res1; | ||
127 | u8 res2[9]; | ||
128 | |||
129 | u8 pll_freq_cmd[PLL_CMD_LEN]; | ||
130 | u8 pll_agc_cmd[PLL_CMD_LEN]; | ||
131 | struct i2c_msg msg[2]; | ||
132 | u32 f; | ||
133 | |||
134 | deb_fe("%s: freq=%d, step=%d\n", __func__, freq, | ||
135 | state->frontend.ops.info.frequency_stepsize); | ||
136 | /* freq -> oscilator frequency conversion. */ | ||
137 | /* freq: 473,000,000 + n*6,000,000 (no 1/7MHz shift to center freq) */ | ||
138 | /* add 400[1/7 MHZ] = 57.142857MHz. 57MHz for the IF, */ | ||
139 | /* 1/7MHz for center freq shift */ | ||
140 | f = freq / state->frontend.ops.info.frequency_stepsize; | ||
141 | f += 400; | ||
142 | pll_freq_cmd[DEMOD_REDIRECT_REG] = JDVBT90502_2ND_I2C_REG; /* 0xFE */ | ||
143 | pll_freq_cmd[ADDRESS_BYTE] = state->config.pll_address << 1; | ||
144 | pll_freq_cmd[DIVIDER_BYTE1] = (f >> 8) & 0x7F; | ||
145 | pll_freq_cmd[DIVIDER_BYTE2] = f & 0xFF; | ||
146 | pll_freq_cmd[CONTROL_BYTE] = 0xB2; /* ref.divider:28, 4MHz/28=1/7MHz */ | ||
147 | pll_freq_cmd[BANDSWITCH_BYTE] = 0x08; /* UHF band */ | ||
148 | |||
149 | msg[0].addr = state->config.demod_address; | ||
150 | msg[0].flags = 0; | ||
151 | msg[0].buf = pll_freq_cmd; | ||
152 | msg[0].len = sizeof(pll_freq_cmd); | ||
153 | |||
154 | ret = i2c_transfer(state->i2c, &msg[0], 1); | ||
155 | if (ret != 1) | ||
156 | goto error; | ||
157 | |||
158 | udelay(50); | ||
159 | |||
160 | pll_agc_cmd[DEMOD_REDIRECT_REG] = pll_freq_cmd[DEMOD_REDIRECT_REG]; | ||
161 | pll_agc_cmd[ADDRESS_BYTE] = pll_freq_cmd[ADDRESS_BYTE]; | ||
162 | pll_agc_cmd[DIVIDER_BYTE1] = pll_freq_cmd[DIVIDER_BYTE1]; | ||
163 | pll_agc_cmd[DIVIDER_BYTE2] = pll_freq_cmd[DIVIDER_BYTE2]; | ||
164 | pll_agc_cmd[CONTROL_BYTE] = 0x9A; /* AGC_CTRL instead of BANDSWITCH */ | ||
165 | pll_agc_cmd[AGC_CTRL_BYTE] = 0x50; | ||
166 | /* AGC Time Constant 2s, AGC take-over point:103dBuV(lowest) */ | ||
167 | |||
168 | msg[1].addr = msg[0].addr; | ||
169 | msg[1].flags = 0; | ||
170 | msg[1].buf = pll_agc_cmd; | ||
171 | msg[1].len = sizeof(pll_agc_cmd); | ||
172 | |||
173 | ret = i2c_transfer(state->i2c, &msg[1], 1); | ||
174 | if (ret != 1) | ||
175 | goto error; | ||
176 | |||
177 | /* I don't know what these cmds are for, */ | ||
178 | /* but the USB log on a windows box contains them */ | ||
179 | ret = jdvbt90502_single_reg_write(state, 0x01, 0x40); | ||
180 | ret |= jdvbt90502_single_reg_write(state, 0x01, 0x00); | ||
181 | if (ret) | ||
182 | goto error; | ||
183 | udelay(100); | ||
184 | |||
185 | /* wait for the demod to be ready? */ | ||
186 | #define RETRY_COUNT 5 | ||
187 | for (retry = 0; retry < RETRY_COUNT; retry++) { | ||
188 | ret = jdvbt90502_reg_read(state, 0x0096, &res1, 1); | ||
189 | if (ret) | ||
190 | goto error; | ||
191 | /* if (res1 != 0x00) goto error; */ | ||
192 | ret = jdvbt90502_reg_read(state, 0x00B0, res2, sizeof(res2)); | ||
193 | if (ret) | ||
194 | goto error; | ||
195 | if (res2[0] >= 0xA7) | ||
196 | break; | ||
197 | msleep(100); | ||
198 | } | ||
199 | if (retry >= RETRY_COUNT) { | ||
200 | deb_fe("%s: FE does not get ready after freq setting.\n", | ||
201 | __func__); | ||
202 | return -EREMOTEIO; | ||
203 | } | ||
204 | |||
205 | return 0; | ||
206 | error: | ||
207 | deb_fe("%s:ret == %d\n", __func__, ret); | ||
208 | return -EREMOTEIO; | ||
209 | } | ||
210 | |||
211 | static int jdvbt90502_read_status(struct dvb_frontend *fe, fe_status_t *state) | ||
212 | { | ||
213 | u8 result; | ||
214 | int ret; | ||
215 | |||
216 | *state = FE_HAS_SIGNAL; | ||
217 | |||
218 | ret = jdvbt90502_pll_read(fe->demodulator_priv, &result); | ||
219 | if (ret) { | ||
220 | deb_fe("%s:ret == %d\n", __func__, ret); | ||
221 | return -EREMOTEIO; | ||
222 | } | ||
223 | |||
224 | *state = FE_HAS_SIGNAL | ||
225 | | FE_HAS_CARRIER | ||
226 | | FE_HAS_VITERBI | ||
227 | | FE_HAS_SYNC; | ||
228 | |||
229 | if (result & PLL_STATUS_LOCKED) | ||
230 | *state |= FE_HAS_LOCK; | ||
231 | |||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | static int jdvbt90502_read_ber(struct dvb_frontend *fe, u32 *ber) | ||
236 | { | ||
237 | *ber = 0; | ||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static int jdvbt90502_read_signal_strength(struct dvb_frontend *fe, | ||
242 | u16 *strength) | ||
243 | { | ||
244 | int ret; | ||
245 | u8 rbuf[37]; | ||
246 | |||
247 | *strength = 0; | ||
248 | |||
249 | /* status register (incl. signal strength) : 0x89 */ | ||
250 | /* TODO: read just the necessary registers [0x8B..0x8D]? */ | ||
251 | ret = jdvbt90502_reg_read(fe->demodulator_priv, 0x0089, | ||
252 | rbuf, sizeof(rbuf)); | ||
253 | |||
254 | if (ret) { | ||
255 | deb_fe("%s:ret == %d\n", __func__, ret); | ||
256 | return -EREMOTEIO; | ||
257 | } | ||
258 | |||
259 | /* signal_strength: rbuf[2-4] (24bit BE), use lower 16bit for now. */ | ||
260 | *strength = (rbuf[3] << 8) + rbuf[4]; | ||
261 | if (rbuf[2]) | ||
262 | *strength = 0xffff; | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static int jdvbt90502_read_snr(struct dvb_frontend *fe, u16 *snr) | ||
268 | { | ||
269 | *snr = 0x0101; | ||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static int jdvbt90502_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) | ||
274 | { | ||
275 | *ucblocks = 0; | ||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | static int jdvbt90502_get_tune_settings(struct dvb_frontend *fe, | ||
280 | struct dvb_frontend_tune_settings *fs) | ||
281 | { | ||
282 | fs->min_delay_ms = 500; | ||
283 | fs->step_size = 0; | ||
284 | fs->max_drift = 0; | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int jdvbt90502_get_frontend(struct dvb_frontend *fe, | ||
290 | struct dvb_frontend_parameters *p) | ||
291 | { | ||
292 | p->inversion = INVERSION_AUTO; | ||
293 | p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ; | ||
294 | p->u.ofdm.code_rate_HP = FEC_AUTO; | ||
295 | p->u.ofdm.code_rate_LP = FEC_AUTO; | ||
296 | p->u.ofdm.constellation = QAM_64; | ||
297 | p->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO; | ||
298 | p->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO; | ||
299 | p->u.ofdm.hierarchy_information = HIERARCHY_AUTO; | ||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static int jdvbt90502_set_frontend(struct dvb_frontend *fe, | ||
304 | struct dvb_frontend_parameters *p) | ||
305 | { | ||
306 | /** | ||
307 | * NOTE: ignore all the paramters except frequency. | ||
308 | * others should be fixed to the proper value for ISDB-T, | ||
309 | * but don't check here. | ||
310 | */ | ||
311 | |||
312 | struct jdvbt90502_state *state = fe->demodulator_priv; | ||
313 | int ret; | ||
314 | |||
315 | deb_fe("%s: Freq:%d\n", __func__, p->frequency); | ||
316 | |||
317 | ret = jdvbt90502_pll_set_freq(state, p->frequency); | ||
318 | if (ret) { | ||
319 | deb_fe("%s:ret == %d\n", __func__, ret); | ||
320 | return -EREMOTEIO; | ||
321 | } | ||
322 | |||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | static int jdvbt90502_sleep(struct dvb_frontend *fe) | ||
327 | { | ||
328 | deb_fe("%s called.\n", __func__); | ||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | |||
333 | /** | ||
334 | * (reg, val) commad list to initialize this module. | ||
335 | * captured on a Windows box. | ||
336 | */ | ||
337 | static u8 init_code[][2] = { | ||
338 | {0x01, 0x40}, | ||
339 | {0x04, 0x38}, | ||
340 | {0x05, 0x40}, | ||
341 | {0x07, 0x40}, | ||
342 | {0x0F, 0x4F}, | ||
343 | {0x11, 0x21}, | ||
344 | {0x12, 0x0B}, | ||
345 | {0x13, 0x2F}, | ||
346 | {0x14, 0x31}, | ||
347 | {0x16, 0x02}, | ||
348 | {0x21, 0xC4}, | ||
349 | {0x22, 0x20}, | ||
350 | {0x2C, 0x79}, | ||
351 | {0x2D, 0x34}, | ||
352 | {0x2F, 0x00}, | ||
353 | {0x30, 0x28}, | ||
354 | {0x31, 0x31}, | ||
355 | {0x32, 0xDF}, | ||
356 | {0x38, 0x01}, | ||
357 | {0x39, 0x78}, | ||
358 | {0x3B, 0x33}, | ||
359 | {0x3C, 0x33}, | ||
360 | {0x48, 0x90}, | ||
361 | {0x51, 0x68}, | ||
362 | {0x5E, 0x38}, | ||
363 | {0x71, 0x00}, | ||
364 | {0x72, 0x08}, | ||
365 | {0x77, 0x00}, | ||
366 | {0xC0, 0x21}, | ||
367 | {0xC1, 0x10}, | ||
368 | {0xE4, 0x1A}, | ||
369 | {0xEA, 0x1F}, | ||
370 | {0x77, 0x00}, | ||
371 | {0x71, 0x00}, | ||
372 | {0x71, 0x00}, | ||
373 | {0x76, 0x0C}, | ||
374 | }; | ||
375 | |||
376 | const static int init_code_len = sizeof(init_code) / sizeof(u8[2]); | ||
377 | |||
378 | static int jdvbt90502_init(struct dvb_frontend *fe) | ||
379 | { | ||
380 | int i = -1; | ||
381 | int ret; | ||
382 | struct i2c_msg msg; | ||
383 | |||
384 | struct jdvbt90502_state *state = fe->demodulator_priv; | ||
385 | |||
386 | deb_fe("%s called.\n", __func__); | ||
387 | |||
388 | msg.addr = state->config.demod_address; | ||
389 | msg.flags = 0; | ||
390 | msg.len = 2; | ||
391 | for (i = 0; i < init_code_len; i++) { | ||
392 | msg.buf = init_code[i]; | ||
393 | ret = i2c_transfer(state->i2c, &msg, 1); | ||
394 | if (ret != 1) | ||
395 | goto error; | ||
396 | } | ||
397 | msleep(100); | ||
398 | |||
399 | return 0; | ||
400 | |||
401 | error: | ||
402 | deb_fe("%s: init_code[%d] failed. ret==%d\n", __func__, i, ret); | ||
403 | return -EREMOTEIO; | ||
404 | } | ||
405 | |||
406 | |||
407 | static void jdvbt90502_release(struct dvb_frontend *fe) | ||
408 | { | ||
409 | struct jdvbt90502_state *state = fe->demodulator_priv; | ||
410 | kfree(state); | ||
411 | } | ||
412 | |||
413 | |||
414 | static struct dvb_frontend_ops jdvbt90502_ops; | ||
415 | |||
416 | struct dvb_frontend *jdvbt90502_attach(struct dvb_usb_device *d) | ||
417 | { | ||
418 | struct jdvbt90502_state *state = NULL; | ||
419 | |||
420 | deb_info("%s called.\n", __func__); | ||
421 | |||
422 | /* allocate memory for the internal state */ | ||
423 | state = kzalloc(sizeof(struct jdvbt90502_state), GFP_KERNEL); | ||
424 | if (state == NULL) | ||
425 | goto error; | ||
426 | |||
427 | /* setup the state */ | ||
428 | state->i2c = &d->i2c_adap; | ||
429 | memcpy(&state->config, &friio_fe_config, sizeof(friio_fe_config)); | ||
430 | |||
431 | /* create dvb_frontend */ | ||
432 | memcpy(&state->frontend.ops, &jdvbt90502_ops, | ||
433 | sizeof(jdvbt90502_ops)); | ||
434 | state->frontend.demodulator_priv = state; | ||
435 | |||
436 | if (jdvbt90502_init(&state->frontend) < 0) | ||
437 | goto error; | ||
438 | |||
439 | return &state->frontend; | ||
440 | |||
441 | error: | ||
442 | kfree(state); | ||
443 | return NULL; | ||
444 | } | ||
445 | |||
446 | static struct dvb_frontend_ops jdvbt90502_ops = { | ||
447 | |||
448 | .info = { | ||
449 | .name = "Comtech JDVBT90502 ISDB-T", | ||
450 | .type = FE_OFDM, | ||
451 | .frequency_min = 473000000, /* UHF 13ch, center */ | ||
452 | .frequency_max = 767142857, /* UHF 62ch, center */ | ||
453 | .frequency_stepsize = JDVBT90502_PLL_CLK / | ||
454 | JDVBT90502_PLL_DIVIDER, | ||
455 | .frequency_tolerance = 0, | ||
456 | |||
457 | /* NOTE: this driver ignores all parameters but frequency. */ | ||
458 | .caps = FE_CAN_INVERSION_AUTO | | ||
459 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | | ||
460 | FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | | ||
461 | FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO | | ||
462 | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | | ||
463 | FE_CAN_TRANSMISSION_MODE_AUTO | | ||
464 | FE_CAN_GUARD_INTERVAL_AUTO | | ||
465 | FE_CAN_HIERARCHY_AUTO, | ||
466 | }, | ||
467 | |||
468 | .release = jdvbt90502_release, | ||
469 | |||
470 | .init = jdvbt90502_init, | ||
471 | .sleep = jdvbt90502_sleep, | ||
472 | .write = _jdvbt90502_write, | ||
473 | |||
474 | .set_frontend = jdvbt90502_set_frontend, | ||
475 | .get_frontend = jdvbt90502_get_frontend, | ||
476 | .get_tune_settings = jdvbt90502_get_tune_settings, | ||
477 | |||
478 | .read_status = jdvbt90502_read_status, | ||
479 | .read_ber = jdvbt90502_read_ber, | ||
480 | .read_signal_strength = jdvbt90502_read_signal_strength, | ||
481 | .read_snr = jdvbt90502_read_snr, | ||
482 | .read_ucblocks = jdvbt90502_read_ucblocks, | ||
483 | }; | ||
diff --git a/drivers/media/dvb/dvb-usb/friio.c b/drivers/media/dvb/dvb-usb/friio.c new file mode 100644 index 000000000000..14a65b4aec07 --- /dev/null +++ b/drivers/media/dvb/dvb-usb/friio.c | |||
@@ -0,0 +1,525 @@ | |||
1 | /* DVB USB compliant Linux driver for the Friio USB2.0 ISDB-T receiver. | ||
2 | * | ||
3 | * Copyright (C) 2009 Akihiro Tsukada <tskd2@yahoo.co.jp> | ||
4 | * | ||
5 | * This module is based off the the gl861 and vp702x modules. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the Free | ||
9 | * Software Foundation, version 2. | ||
10 | * | ||
11 | * see Documentation/dvb/README.dvb-usb for more information | ||
12 | */ | ||
13 | #include "friio.h" | ||
14 | |||
15 | /* debug */ | ||
16 | int dvb_usb_friio_debug; | ||
17 | module_param_named(debug, dvb_usb_friio_debug, int, 0644); | ||
18 | MODULE_PARM_DESC(debug, | ||
19 | "set debugging level (1=info,2=xfer,4=rc,8=fe (or-able))." | ||
20 | DVB_USB_DEBUG_STATUS); | ||
21 | |||
22 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
23 | |||
24 | /** | ||
25 | * Indirect I2C access to the PLL via FE. | ||
26 | * whole I2C protocol data to the PLL is sent via the FE's I2C register. | ||
27 | * This is done by a control msg to the FE with the I2C data accompanied, and | ||
28 | * a specific USB request number is assigned for that purpose. | ||
29 | * | ||
30 | * this func sends wbuf[1..] to the I2C register wbuf[0] at addr (= at FE). | ||
31 | * TODO: refoctored, smarter i2c functions. | ||
32 | */ | ||
33 | static int gl861_i2c_ctrlmsg_data(struct dvb_usb_device *d, u8 addr, | ||
34 | u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) | ||
35 | { | ||
36 | u16 index = wbuf[0]; /* must be JDVBT90502_2ND_I2C_REG(=0xFE) */ | ||
37 | u16 value = addr << (8 + 1); | ||
38 | int wo = (rbuf == NULL || rlen == 0); /* write only */ | ||
39 | u8 req, type; | ||
40 | |||
41 | deb_xfer("write to PLL:0x%02x via FE reg:0x%02x, len:%d\n", | ||
42 | wbuf[1], wbuf[0], wlen - 1); | ||
43 | |||
44 | if (wo && wlen >= 2) { | ||
45 | req = GL861_REQ_I2C_DATA_CTRL_WRITE; | ||
46 | type = GL861_WRITE; | ||
47 | udelay(20); | ||
48 | return usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), | ||
49 | req, type, value, index, | ||
50 | &wbuf[1], wlen - 1, 2000); | ||
51 | } | ||
52 | |||
53 | deb_xfer("not supported ctrl-msg, aborting."); | ||
54 | return -EINVAL; | ||
55 | } | ||
56 | |||
57 | /* normal I2C access (without extra data arguments). | ||
58 | * write to the register wbuf[0] at I2C address addr with the value wbuf[1], | ||
59 | * or read from the register wbuf[0]. | ||
60 | * register address can be 16bit (wbuf[2]<<8 | wbuf[0]) if wlen==3 | ||
61 | */ | ||
62 | static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, | ||
63 | u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) | ||
64 | { | ||
65 | u16 index; | ||
66 | u16 value = addr << (8 + 1); | ||
67 | int wo = (rbuf == NULL || rlen == 0); /* write-only */ | ||
68 | u8 req, type; | ||
69 | unsigned int pipe; | ||
70 | |||
71 | /* special case for the indirect I2C access to the PLL via FE, */ | ||
72 | if (addr == friio_fe_config.demod_address && | ||
73 | wbuf[0] == JDVBT90502_2ND_I2C_REG) | ||
74 | return gl861_i2c_ctrlmsg_data(d, addr, wbuf, wlen, rbuf, rlen); | ||
75 | |||
76 | if (wo) { | ||
77 | req = GL861_REQ_I2C_WRITE; | ||
78 | type = GL861_WRITE; | ||
79 | pipe = usb_sndctrlpipe(d->udev, 0); | ||
80 | } else { /* rw */ | ||
81 | req = GL861_REQ_I2C_READ; | ||
82 | type = GL861_READ; | ||
83 | pipe = usb_rcvctrlpipe(d->udev, 0); | ||
84 | } | ||
85 | |||
86 | switch (wlen) { | ||
87 | case 1: | ||
88 | index = wbuf[0]; | ||
89 | break; | ||
90 | case 2: | ||
91 | index = wbuf[0]; | ||
92 | value = value + wbuf[1]; | ||
93 | break; | ||
94 | case 3: | ||
95 | /* special case for 16bit register-address */ | ||
96 | index = (wbuf[2] << 8) | wbuf[0]; | ||
97 | value = value + wbuf[1]; | ||
98 | break; | ||
99 | default: | ||
100 | deb_xfer("wlen = %x, aborting.", wlen); | ||
101 | return -EINVAL; | ||
102 | } | ||
103 | msleep(1); | ||
104 | return usb_control_msg(d->udev, pipe, req, type, | ||
105 | value, index, rbuf, rlen, 2000); | ||
106 | } | ||
107 | |||
108 | /* I2C */ | ||
109 | static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], | ||
110 | int num) | ||
111 | { | ||
112 | struct dvb_usb_device *d = i2c_get_adapdata(adap); | ||
113 | int i; | ||
114 | |||
115 | |||
116 | if (num > 2) | ||
117 | return -EINVAL; | ||
118 | |||
119 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) | ||
120 | return -EAGAIN; | ||
121 | |||
122 | for (i = 0; i < num; i++) { | ||
123 | /* write/read request */ | ||
124 | if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD)) { | ||
125 | if (gl861_i2c_msg(d, msg[i].addr, | ||
126 | msg[i].buf, msg[i].len, | ||
127 | msg[i + 1].buf, msg[i + 1].len) < 0) | ||
128 | break; | ||
129 | i++; | ||
130 | } else | ||
131 | if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf, | ||
132 | msg[i].len, NULL, 0) < 0) | ||
133 | break; | ||
134 | } | ||
135 | |||
136 | mutex_unlock(&d->i2c_mutex); | ||
137 | return i; | ||
138 | } | ||
139 | |||
140 | static u32 gl861_i2c_func(struct i2c_adapter *adapter) | ||
141 | { | ||
142 | return I2C_FUNC_I2C; | ||
143 | } | ||
144 | |||
145 | |||
146 | static int friio_ext_ctl(struct dvb_usb_adapter *adap, | ||
147 | u32 sat_color, int lnb_on) | ||
148 | { | ||
149 | int i; | ||
150 | int ret; | ||
151 | struct i2c_msg msg; | ||
152 | u8 buf[2]; | ||
153 | u32 mask; | ||
154 | u8 lnb = (lnb_on) ? FRIIO_CTL_LNB : 0; | ||
155 | |||
156 | msg.addr = 0x00; | ||
157 | msg.flags = 0; | ||
158 | msg.len = 2; | ||
159 | msg.buf = buf; | ||
160 | |||
161 | buf[0] = 0x00; | ||
162 | |||
163 | /* send 2bit header (&B10) */ | ||
164 | buf[1] = lnb | FRIIO_CTL_LED | FRIIO_CTL_STROBE; | ||
165 | ret = gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
166 | buf[1] |= FRIIO_CTL_CLK; | ||
167 | ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
168 | |||
169 | buf[1] = lnb | FRIIO_CTL_STROBE; | ||
170 | ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
171 | buf[1] |= FRIIO_CTL_CLK; | ||
172 | ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
173 | |||
174 | /* send 32bit(satur, R, G, B) data in serial */ | ||
175 | mask = 1 << 31; | ||
176 | for (i = 0; i < 32; i++) { | ||
177 | buf[1] = lnb | FRIIO_CTL_STROBE; | ||
178 | if (sat_color & mask) | ||
179 | buf[1] |= FRIIO_CTL_LED; | ||
180 | ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
181 | buf[1] |= FRIIO_CTL_CLK; | ||
182 | ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
183 | mask >>= 1; | ||
184 | } | ||
185 | |||
186 | /* set the strobe off */ | ||
187 | buf[1] = lnb; | ||
188 | ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
189 | buf[1] |= FRIIO_CTL_CLK; | ||
190 | ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); | ||
191 | |||
192 | return (ret == 70); | ||
193 | } | ||
194 | |||
195 | |||
196 | static int friio_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff); | ||
197 | |||
198 | /* TODO: move these init cmds to the FE's init routine? */ | ||
199 | static u8 streaming_init_cmds[][2] = { | ||
200 | {0x33, 0x08}, | ||
201 | {0x37, 0x40}, | ||
202 | {0x3A, 0x1F}, | ||
203 | {0x3B, 0xFF}, | ||
204 | {0x3C, 0x1F}, | ||
205 | {0x3D, 0xFF}, | ||
206 | {0x38, 0x00}, | ||
207 | {0x35, 0x00}, | ||
208 | {0x39, 0x00}, | ||
209 | {0x36, 0x00}, | ||
210 | }; | ||
211 | static int cmdlen = sizeof(streaming_init_cmds) / 2; | ||
212 | |||
213 | /* | ||
214 | * Command sequence in this init function is a replay | ||
215 | * of the captured USB commands from the Windows proprietary driver. | ||
216 | */ | ||
217 | static int friio_initialize(struct dvb_usb_device *d) | ||
218 | { | ||
219 | int ret; | ||
220 | int i; | ||
221 | int retry = 0; | ||
222 | u8 rbuf[2]; | ||
223 | u8 wbuf[3]; | ||
224 | |||
225 | deb_info("%s called.\n", __func__); | ||
226 | |||
227 | /* use gl861_i2c_msg instead of gl861_i2c_xfer(), */ | ||
228 | /* because the i2c device is not set up yet. */ | ||
229 | wbuf[0] = 0x11; | ||
230 | wbuf[1] = 0x02; | ||
231 | ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); | ||
232 | if (ret < 0) | ||
233 | goto error; | ||
234 | msleep(2); | ||
235 | |||
236 | wbuf[0] = 0x11; | ||
237 | wbuf[1] = 0x00; | ||
238 | ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); | ||
239 | if (ret < 0) | ||
240 | goto error; | ||
241 | msleep(1); | ||
242 | |||
243 | /* following msgs should be in the FE's init code? */ | ||
244 | /* cmd sequence to identify the device type? (friio black/white) */ | ||
245 | wbuf[0] = 0x03; | ||
246 | wbuf[1] = 0x80; | ||
247 | /* can't use gl861_i2c_cmd, as the register-addr is 16bit(0x0100) */ | ||
248 | ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), | ||
249 | GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE, | ||
250 | 0x1200, 0x0100, wbuf, 2, 2000); | ||
251 | if (ret < 0) | ||
252 | goto error; | ||
253 | |||
254 | msleep(2); | ||
255 | wbuf[0] = 0x00; | ||
256 | wbuf[2] = 0x01; /* reg.0x0100 */ | ||
257 | wbuf[1] = 0x00; | ||
258 | ret = gl861_i2c_msg(d, 0x12 >> 1, wbuf, 3, rbuf, 2); | ||
259 | /* my Friio White returns 0xffff. */ | ||
260 | if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff) | ||
261 | goto error; | ||
262 | |||
263 | msleep(2); | ||
264 | wbuf[0] = 0x03; | ||
265 | wbuf[1] = 0x80; | ||
266 | ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), | ||
267 | GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE, | ||
268 | 0x9000, 0x0100, wbuf, 2, 2000); | ||
269 | if (ret < 0) | ||
270 | goto error; | ||
271 | |||
272 | msleep(2); | ||
273 | wbuf[0] = 0x00; | ||
274 | wbuf[2] = 0x01; /* reg.0x0100 */ | ||
275 | wbuf[1] = 0x00; | ||
276 | ret = gl861_i2c_msg(d, 0x90 >> 1, wbuf, 3, rbuf, 2); | ||
277 | /* my Friio White returns 0xffff again. */ | ||
278 | if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff) | ||
279 | goto error; | ||
280 | |||
281 | msleep(1); | ||
282 | |||
283 | restart: | ||
284 | /* ============ start DEMOD init cmds ================== */ | ||
285 | /* read PLL status to clear the POR bit */ | ||
286 | wbuf[0] = JDVBT90502_2ND_I2C_REG; | ||
287 | wbuf[1] = (FRIIO_PLL_ADDR << 1) + 1; /* +1 for reading */ | ||
288 | ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 2, NULL, 0); | ||
289 | if (ret < 0) | ||
290 | goto error; | ||
291 | |||
292 | msleep(5); | ||
293 | /* note: DEMODULATOR has 16bit register-address. */ | ||
294 | wbuf[0] = 0x00; | ||
295 | wbuf[2] = 0x01; /* reg addr: 0x0100 */ | ||
296 | wbuf[1] = 0x00; /* val: not used */ | ||
297 | ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 3, rbuf, 1); | ||
298 | if (ret < 0) | ||
299 | goto error; | ||
300 | /* | ||
301 | msleep(1); | ||
302 | wbuf[0] = 0x80; | ||
303 | wbuf[1] = 0x00; | ||
304 | ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 2, rbuf, 1); | ||
305 | if (ret < 0) | ||
306 | goto error; | ||
307 | */ | ||
308 | if (rbuf[0] & 0x80) { /* still in PowerOnReset state? */ | ||
309 | if (++retry > 3) { | ||
310 | deb_info("failed to get the correct" | ||
311 | " FE demod status:0x%02x\n", rbuf[0]); | ||
312 | goto error; | ||
313 | } | ||
314 | msleep(100); | ||
315 | goto restart; | ||
316 | } | ||
317 | |||
318 | /* TODO: check return value in rbuf */ | ||
319 | /* =========== end DEMOD init cmds ===================== */ | ||
320 | msleep(1); | ||
321 | |||
322 | wbuf[0] = 0x30; | ||
323 | wbuf[1] = 0x04; | ||
324 | ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); | ||
325 | if (ret < 0) | ||
326 | goto error; | ||
327 | |||
328 | msleep(2); | ||
329 | /* following 2 cmds unnecessary? */ | ||
330 | wbuf[0] = 0x00; | ||
331 | wbuf[1] = 0x01; | ||
332 | ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); | ||
333 | if (ret < 0) | ||
334 | goto error; | ||
335 | |||
336 | wbuf[0] = 0x06; | ||
337 | wbuf[1] = 0x0F; | ||
338 | ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); | ||
339 | if (ret < 0) | ||
340 | goto error; | ||
341 | |||
342 | /* some streaming ctl cmds (maybe) */ | ||
343 | msleep(10); | ||
344 | for (i = 0; i < cmdlen; i++) { | ||
345 | ret = gl861_i2c_msg(d, 0x00, streaming_init_cmds[i], 2, | ||
346 | NULL, 0); | ||
347 | if (ret < 0) | ||
348 | goto error; | ||
349 | msleep(1); | ||
350 | } | ||
351 | msleep(20); | ||
352 | |||
353 | /* change the LED color etc. */ | ||
354 | ret = friio_streaming_ctrl(&d->adapter[0], 0); | ||
355 | if (ret < 0) | ||
356 | goto error; | ||
357 | |||
358 | return 0; | ||
359 | |||
360 | error: | ||
361 | deb_info("%s:ret == %d\n", __func__, ret); | ||
362 | return -EIO; | ||
363 | } | ||
364 | |||
365 | /* Callbacks for DVB USB */ | ||
366 | |||
367 | static int friio_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) | ||
368 | { | ||
369 | int ret; | ||
370 | |||
371 | deb_info("%s called.(%d)\n", __func__, onoff); | ||
372 | |||
373 | /* set the LED color and saturation (and LNB on) */ | ||
374 | if (onoff) | ||
375 | ret = friio_ext_ctl(adap, 0x6400ff64, 1); | ||
376 | else | ||
377 | ret = friio_ext_ctl(adap, 0x96ff00ff, 1); | ||
378 | |||
379 | if (ret != 1) { | ||
380 | deb_info("%s failed to send cmdx. ret==%d\n", __func__, ret); | ||
381 | return -EREMOTEIO; | ||
382 | } | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | static int friio_frontend_attach(struct dvb_usb_adapter *adap) | ||
387 | { | ||
388 | if (friio_initialize(adap->dev) < 0) | ||
389 | return -EIO; | ||
390 | |||
391 | adap->fe = jdvbt90502_attach(adap->dev); | ||
392 | if (adap->fe == NULL) | ||
393 | return -EIO; | ||
394 | |||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | /* DVB USB Driver stuff */ | ||
399 | static struct dvb_usb_device_properties friio_properties; | ||
400 | |||
401 | static int friio_probe(struct usb_interface *intf, | ||
402 | const struct usb_device_id *id) | ||
403 | { | ||
404 | struct dvb_usb_device *d; | ||
405 | struct usb_host_interface *alt; | ||
406 | int ret; | ||
407 | |||
408 | if (intf->num_altsetting < GL861_ALTSETTING_COUNT) | ||
409 | return -ENODEV; | ||
410 | |||
411 | alt = usb_altnum_to_altsetting(intf, FRIIO_BULK_ALTSETTING); | ||
412 | if (alt == NULL) { | ||
413 | deb_rc("not alt found!\n"); | ||
414 | return -ENODEV; | ||
415 | } | ||
416 | ret = usb_set_interface(interface_to_usbdev(intf), | ||
417 | alt->desc.bInterfaceNumber, | ||
418 | alt->desc.bAlternateSetting); | ||
419 | if (ret != 0) { | ||
420 | deb_rc("failed to set alt-setting!\n"); | ||
421 | return ret; | ||
422 | } | ||
423 | |||
424 | ret = dvb_usb_device_init(intf, &friio_properties, | ||
425 | THIS_MODULE, &d, adapter_nr); | ||
426 | if (ret == 0) | ||
427 | friio_streaming_ctrl(&d->adapter[0], 1); | ||
428 | |||
429 | return ret; | ||
430 | } | ||
431 | |||
432 | |||
433 | struct jdvbt90502_config friio_fe_config = { | ||
434 | .demod_address = FRIIO_DEMOD_ADDR, | ||
435 | .pll_address = FRIIO_PLL_ADDR, | ||
436 | }; | ||
437 | |||
438 | static struct i2c_algorithm gl861_i2c_algo = { | ||
439 | .master_xfer = gl861_i2c_xfer, | ||
440 | .functionality = gl861_i2c_func, | ||
441 | }; | ||
442 | |||
443 | static struct usb_device_id friio_table[] = { | ||
444 | { USB_DEVICE(USB_VID_774, USB_PID_FRIIO_WHITE) }, | ||
445 | { } /* Terminating entry */ | ||
446 | }; | ||
447 | MODULE_DEVICE_TABLE(usb, friio_table); | ||
448 | |||
449 | |||
450 | static struct dvb_usb_device_properties friio_properties = { | ||
451 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | ||
452 | .usb_ctrl = DEVICE_SPECIFIC, | ||
453 | |||
454 | .size_of_priv = 0, | ||
455 | |||
456 | .num_adapters = 1, | ||
457 | .adapter = { | ||
458 | /* caps:0 => no pid filter, 188B TS packet */ | ||
459 | /* GL861 has a HW pid filter, but no info available. */ | ||
460 | { | ||
461 | .caps = 0, | ||
462 | |||
463 | .frontend_attach = friio_frontend_attach, | ||
464 | .streaming_ctrl = friio_streaming_ctrl, | ||
465 | |||
466 | .stream = { | ||
467 | .type = USB_BULK, | ||
468 | /* count <= MAX_NO_URBS_FOR_DATA_STREAM(10) */ | ||
469 | .count = 8, | ||
470 | .endpoint = 0x01, | ||
471 | .u = { | ||
472 | /* GL861 has 6KB buf inside */ | ||
473 | .bulk = { | ||
474 | .buffersize = 16384, | ||
475 | } | ||
476 | } | ||
477 | }, | ||
478 | } | ||
479 | }, | ||
480 | .i2c_algo = &gl861_i2c_algo, | ||
481 | |||
482 | .num_device_descs = 1, | ||
483 | .devices = { | ||
484 | { | ||
485 | .name = "774 Friio ISDB-T USB2.0", | ||
486 | .cold_ids = { NULL }, | ||
487 | .warm_ids = { &friio_table[0], NULL }, | ||
488 | }, | ||
489 | } | ||
490 | }; | ||
491 | |||
492 | static struct usb_driver friio_driver = { | ||
493 | .name = "dvb_usb_friio", | ||
494 | .probe = friio_probe, | ||
495 | .disconnect = dvb_usb_device_exit, | ||
496 | .id_table = friio_table, | ||
497 | }; | ||
498 | |||
499 | |||
500 | /* module stuff */ | ||
501 | static int __init friio_module_init(void) | ||
502 | { | ||
503 | int ret; | ||
504 | |||
505 | ret = usb_register(&friio_driver); | ||
506 | if (ret) | ||
507 | err("usb_register failed. Error number %d", ret); | ||
508 | |||
509 | return ret; | ||
510 | } | ||
511 | |||
512 | |||
513 | static void __exit friio_module_exit(void) | ||
514 | { | ||
515 | /* deregister this driver from the USB subsystem */ | ||
516 | usb_deregister(&friio_driver); | ||
517 | } | ||
518 | |||
519 | module_init(friio_module_init); | ||
520 | module_exit(friio_module_exit); | ||
521 | |||
522 | MODULE_AUTHOR("Akihiro Tsukada <tskd2@yahoo.co.jp>"); | ||
523 | MODULE_DESCRIPTION("Driver for Friio ISDB-T USB2.0 Receiver"); | ||
524 | MODULE_VERSION("0.2"); | ||
525 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/dvb/dvb-usb/friio.h b/drivers/media/dvb/dvb-usb/friio.h new file mode 100644 index 000000000000..af8d55e390fb --- /dev/null +++ b/drivers/media/dvb/dvb-usb/friio.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* DVB USB compliant Linux driver for the Friio USB2.0 ISDB-T receiver. | ||
2 | * | ||
3 | * Copyright (C) 2009 Akihiro Tsukada <tskd2@yahoo.co.jp> | ||
4 | * | ||
5 | * This module is based off the the gl861 and vp702x modules. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the Free | ||
9 | * Software Foundation, version 2. | ||
10 | * | ||
11 | * see Documentation/dvb/README.dvb-usb for more information | ||
12 | */ | ||
13 | #ifndef _DVB_USB_FRIIO_H_ | ||
14 | #define _DVB_USB_FRIIO_H_ | ||
15 | |||
16 | /** | ||
17 | * Friio Components | ||
18 | * USB hub: AU4254 | ||
19 | * USB controller(+ TS dmx & streaming): GL861 | ||
20 | * Frontend: comtech JDVBT-90502 | ||
21 | * (tuner PLL: tua6034, I2C addr:(0xC0 >> 1)) | ||
22 | * (OFDM demodulator: TC90502, I2C addr:(0x30 >> 1)) | ||
23 | * LED x3 (+LNB) controll: PIC 16F676 | ||
24 | * EEPROM: 24C08 | ||
25 | * | ||
26 | * (USB smart card reader: AU9522) | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #define DVB_USB_LOG_PREFIX "friio" | ||
31 | #include "dvb-usb.h" | ||
32 | |||
33 | extern int dvb_usb_friio_debug; | ||
34 | #define deb_info(args...) dprintk(dvb_usb_friio_debug, 0x01, args) | ||
35 | #define deb_xfer(args...) dprintk(dvb_usb_friio_debug, 0x02, args) | ||
36 | #define deb_rc(args...) dprintk(dvb_usb_friio_debug, 0x04, args) | ||
37 | #define deb_fe(args...) dprintk(dvb_usb_friio_debug, 0x08, args) | ||
38 | |||
39 | /* Vendor requests */ | ||
40 | #define GL861_WRITE 0x40 | ||
41 | #define GL861_READ 0xc0 | ||
42 | |||
43 | /* command bytes */ | ||
44 | #define GL861_REQ_I2C_WRITE 0x01 | ||
45 | #define GL861_REQ_I2C_READ 0x02 | ||
46 | /* For control msg with data argument */ | ||
47 | /* Used for accessing the PLL on the secondary I2C bus of FE via GL861 */ | ||
48 | #define GL861_REQ_I2C_DATA_CTRL_WRITE 0x03 | ||
49 | |||
50 | #define GL861_ALTSETTING_COUNT 2 | ||
51 | #define FRIIO_BULK_ALTSETTING 0 | ||
52 | #define FRIIO_ISOC_ALTSETTING 1 | ||
53 | |||
54 | /* LED & LNB control via PIC. */ | ||
55 | /* basically, it's serial control with clock and strobe. */ | ||
56 | /* write the below 4bit control data to the reg 0x00 at the I2C addr 0x00 */ | ||
57 | /* when controlling the LEDs, 32bit(saturation, R, G, B) is sent on the bit3*/ | ||
58 | #define FRIIO_CTL_LNB (1 << 0) | ||
59 | #define FRIIO_CTL_STROBE (1 << 1) | ||
60 | #define FRIIO_CTL_CLK (1 << 2) | ||
61 | #define FRIIO_CTL_LED (1 << 3) | ||
62 | |||
63 | /* Front End related */ | ||
64 | |||
65 | #define FRIIO_DEMOD_ADDR (0x30 >> 1) | ||
66 | #define FRIIO_PLL_ADDR (0xC0 >> 1) | ||
67 | |||
68 | #define JDVBT90502_PLL_CLK 4000000 | ||
69 | #define JDVBT90502_PLL_DIVIDER 28 | ||
70 | |||
71 | #define JDVBT90502_2ND_I2C_REG 0xFE | ||
72 | |||
73 | /* byte index for pll i2c command data structure*/ | ||
74 | /* see datasheet for tua6034 */ | ||
75 | #define DEMOD_REDIRECT_REG 0 | ||
76 | #define ADDRESS_BYTE 1 | ||
77 | #define DIVIDER_BYTE1 2 | ||
78 | #define DIVIDER_BYTE2 3 | ||
79 | #define CONTROL_BYTE 4 | ||
80 | #define BANDSWITCH_BYTE 5 | ||
81 | #define AGC_CTRL_BYTE 5 | ||
82 | #define PLL_CMD_LEN 6 | ||
83 | |||
84 | /* bit masks for PLL STATUS response */ | ||
85 | #define PLL_STATUS_POR_MODE 0x80 /* 1: Power on Reset (test) Mode */ | ||
86 | #define PLL_STATUS_LOCKED 0x40 /* 1: locked */ | ||
87 | #define PLL_STATUS_AGC_ACTIVE 0x08 /* 1:active */ | ||
88 | #define PLL_STATUS_TESTMODE 0x07 /* digital output level (5 level) */ | ||
89 | /* 0.15Vcc step 0x00: < 0.15Vcc, ..., 0x04: >= 0.6Vcc (<= 1Vcc) */ | ||
90 | |||
91 | |||
92 | struct jdvbt90502_config { | ||
93 | u8 demod_address; /* i2c addr for demodulator IC */ | ||
94 | u8 pll_address; /* PLL addr on the secondary i2c*/ | ||
95 | }; | ||
96 | extern struct jdvbt90502_config friio_fe_config; | ||
97 | |||
98 | extern struct dvb_frontend *jdvbt90502_attach(struct dvb_usb_device *d); | ||
99 | #endif | ||