aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorentin Labbe <clabbe@baylibre.com>2018-09-26 07:44:20 -0400
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-12-05 03:25:41 -0500
commitaaef6a9dd0ea7f824a53cfc556bb621e207cefe7 (patch)
tree4c3c1e5d676754ad43a3575a354a9d3b9ba41117
parentd3411f656cbba9c3cfb85644189f83ce159c6e29 (diff)
media: usb: dvb-usb: remove old friio driver
friio drivers is unused and un-compilable since commit b30cc07de8a9 ("media: dvb-usb/friio, dvb-usb-v2/gl861: decompose friio and merge with gl861"). Let's remove it. Signed-off-by: Corentin Labbe <clabbe@baylibre.com> Cc: Akihiro Tsukada <tskd2@yahoo.co.jp> Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
-rw-r--r--drivers/media/usb/dvb-usb/friio-fe.c440
-rw-r--r--drivers/media/usb/dvb-usb/friio.c522
-rw-r--r--drivers/media/usb/dvb-usb/friio.h99
3 files changed, 0 insertions, 1061 deletions
diff --git a/drivers/media/usb/dvb-usb/friio-fe.c b/drivers/media/usb/dvb-usb/friio-fe.c
deleted file mode 100644
index e6bd0ed8d789..000000000000
--- a/drivers/media/usb/dvb-usb/friio-fe.c
+++ /dev/null
@@ -1,440 +0,0 @@
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/media/dvb-drivers/dvb-usb.rst for more information
12 */
13#include <linux/init.h>
14#include <linux/string.h>
15#include <linux/slab.h>
16#include <linux/kernel.h>
17
18#include "friio.h"
19
20struct jdvbt90502_state {
21 struct i2c_adapter *i2c;
22 struct dvb_frontend frontend;
23 struct jdvbt90502_config config;
24};
25
26/* NOTE: TC90502 has 16bit register-address? */
27/* register 0x0100 is used for reading PLL status, so reg is u16 here */
28static int jdvbt90502_reg_read(struct jdvbt90502_state *state,
29 const u16 reg, u8 *buf, const size_t count)
30{
31 int ret;
32 u8 wbuf[3];
33 struct i2c_msg msg[2];
34
35 wbuf[0] = reg & 0xFF;
36 wbuf[1] = 0;
37 wbuf[2] = reg >> 8;
38
39 msg[0].addr = state->config.demod_address;
40 msg[0].flags = 0;
41 msg[0].buf = wbuf;
42 msg[0].len = sizeof(wbuf);
43
44 msg[1].addr = msg[0].addr;
45 msg[1].flags = I2C_M_RD;
46 msg[1].buf = buf;
47 msg[1].len = count;
48
49 ret = i2c_transfer(state->i2c, msg, 2);
50 if (ret != 2) {
51 deb_fe(" reg read failed.\n");
52 return -EREMOTEIO;
53 }
54 return 0;
55}
56
57/* currently 16bit register-address is not used, so reg is u8 here */
58static int jdvbt90502_single_reg_write(struct jdvbt90502_state *state,
59 const u8 reg, const u8 val)
60{
61 struct i2c_msg msg;
62 u8 wbuf[2];
63
64 wbuf[0] = reg;
65 wbuf[1] = val;
66
67 msg.addr = state->config.demod_address;
68 msg.flags = 0;
69 msg.buf = wbuf;
70 msg.len = sizeof(wbuf);
71
72 if (i2c_transfer(state->i2c, &msg, 1) != 1) {
73 deb_fe(" reg write failed.");
74 return -EREMOTEIO;
75 }
76 return 0;
77}
78
79static int _jdvbt90502_write(struct dvb_frontend *fe, const u8 buf[], int len)
80{
81 struct jdvbt90502_state *state = fe->demodulator_priv;
82 int err, i;
83 for (i = 0; i < len - 1; i++) {
84 err = jdvbt90502_single_reg_write(state,
85 buf[0] + i, buf[i + 1]);
86 if (err)
87 return err;
88 }
89
90 return 0;
91}
92
93/* read pll status byte via the demodulator's I2C register */
94/* note: Win box reads it by 8B block at the I2C addr 0x30 from reg:0x80 */
95static int jdvbt90502_pll_read(struct jdvbt90502_state *state, u8 *result)
96{
97 int ret;
98
99 /* +1 for reading */
100 u8 pll_addr_byte = (state->config.pll_address << 1) + 1;
101
102 *result = 0;
103
104 ret = jdvbt90502_single_reg_write(state, JDVBT90502_2ND_I2C_REG,
105 pll_addr_byte);
106 if (ret)
107 goto error;
108
109 ret = jdvbt90502_reg_read(state, 0x0100, result, 1);
110 if (ret)
111 goto error;
112
113 deb_fe("PLL read val:%02x\n", *result);
114 return 0;
115
116error:
117 deb_fe("%s:ret == %d\n", __func__, ret);
118 return -EREMOTEIO;
119}
120
121
122/* set pll frequency via the demodulator's I2C register */
123static int jdvbt90502_pll_set_freq(struct jdvbt90502_state *state, u32 freq)
124{
125 int ret;
126 int retry;
127 u8 res1;
128 u8 res2[9];
129
130 u8 pll_freq_cmd[PLL_CMD_LEN];
131 u8 pll_agc_cmd[PLL_CMD_LEN];
132 struct i2c_msg msg[2];
133 u32 f;
134
135 deb_fe("%s: freq=%d, step=%d\n", __func__, freq,
136 state->frontend.ops.info.frequency_stepsize_hz);
137 /* freq -> oscilator frequency conversion. */
138 /* freq: 473,000,000 + n*6,000,000 [+ 142857 (center freq. shift)] */
139 f = freq / state->frontend.ops.info.frequency_stepsize_hz;
140 /* add 399[1/7 MHZ] = 57MHz for the IF */
141 f += 399;
142 /* add center frequency shift if necessary */
143 if (f % 7 == 0)
144 f++;
145 pll_freq_cmd[DEMOD_REDIRECT_REG] = JDVBT90502_2ND_I2C_REG; /* 0xFE */
146 pll_freq_cmd[ADDRESS_BYTE] = state->config.pll_address << 1;
147 pll_freq_cmd[DIVIDER_BYTE1] = (f >> 8) & 0x7F;
148 pll_freq_cmd[DIVIDER_BYTE2] = f & 0xFF;
149 pll_freq_cmd[CONTROL_BYTE] = 0xB2; /* ref.divider:28, 4MHz/28=1/7MHz */
150 pll_freq_cmd[BANDSWITCH_BYTE] = 0x08; /* UHF band */
151
152 msg[0].addr = state->config.demod_address;
153 msg[0].flags = 0;
154 msg[0].buf = pll_freq_cmd;
155 msg[0].len = sizeof(pll_freq_cmd);
156
157 ret = i2c_transfer(state->i2c, &msg[0], 1);
158 if (ret != 1)
159 goto error;
160
161 udelay(50);
162
163 pll_agc_cmd[DEMOD_REDIRECT_REG] = pll_freq_cmd[DEMOD_REDIRECT_REG];
164 pll_agc_cmd[ADDRESS_BYTE] = pll_freq_cmd[ADDRESS_BYTE];
165 pll_agc_cmd[DIVIDER_BYTE1] = pll_freq_cmd[DIVIDER_BYTE1];
166 pll_agc_cmd[DIVIDER_BYTE2] = pll_freq_cmd[DIVIDER_BYTE2];
167 pll_agc_cmd[CONTROL_BYTE] = 0x9A; /* AGC_CTRL instead of BANDSWITCH */
168 pll_agc_cmd[AGC_CTRL_BYTE] = 0x50;
169 /* AGC Time Constant 2s, AGC take-over point:103dBuV(lowest) */
170
171 msg[1].addr = msg[0].addr;
172 msg[1].flags = 0;
173 msg[1].buf = pll_agc_cmd;
174 msg[1].len = sizeof(pll_agc_cmd);
175
176 ret = i2c_transfer(state->i2c, &msg[1], 1);
177 if (ret != 1)
178 goto error;
179
180 /* I don't know what these cmds are for, */
181 /* but the USB log on a windows box contains them */
182 ret = jdvbt90502_single_reg_write(state, 0x01, 0x40);
183 ret |= jdvbt90502_single_reg_write(state, 0x01, 0x00);
184 if (ret)
185 goto error;
186 udelay(100);
187
188 /* wait for the demod to be ready? */
189#define RETRY_COUNT 5
190 for (retry = 0; retry < RETRY_COUNT; retry++) {
191 ret = jdvbt90502_reg_read(state, 0x0096, &res1, 1);
192 if (ret)
193 goto error;
194 /* if (res1 != 0x00) goto error; */
195 ret = jdvbt90502_reg_read(state, 0x00B0, res2, sizeof(res2));
196 if (ret)
197 goto error;
198 if (res2[0] >= 0xA7)
199 break;
200 msleep(100);
201 }
202 if (retry >= RETRY_COUNT) {
203 deb_fe("%s: FE does not get ready after freq setting.\n",
204 __func__);
205 return -EREMOTEIO;
206 }
207
208 return 0;
209error:
210 deb_fe("%s:ret == %d\n", __func__, ret);
211 return -EREMOTEIO;
212}
213
214static int jdvbt90502_read_status(struct dvb_frontend *fe,
215 enum fe_status *state)
216{
217 u8 result;
218 int ret;
219
220 *state = FE_HAS_SIGNAL;
221
222 ret = jdvbt90502_pll_read(fe->demodulator_priv, &result);
223 if (ret) {
224 deb_fe("%s:ret == %d\n", __func__, ret);
225 return -EREMOTEIO;
226 }
227
228 *state = FE_HAS_SIGNAL
229 | FE_HAS_CARRIER
230 | FE_HAS_VITERBI
231 | FE_HAS_SYNC;
232
233 if (result & PLL_STATUS_LOCKED)
234 *state |= FE_HAS_LOCK;
235
236 return 0;
237}
238
239static int jdvbt90502_read_signal_strength(struct dvb_frontend *fe,
240 u16 *strength)
241{
242 int ret;
243 u8 rbuf[37];
244
245 *strength = 0;
246
247 /* status register (incl. signal strength) : 0x89 */
248 /* TODO: read just the necessary registers [0x8B..0x8D]? */
249 ret = jdvbt90502_reg_read(fe->demodulator_priv, 0x0089,
250 rbuf, sizeof(rbuf));
251
252 if (ret) {
253 deb_fe("%s:ret == %d\n", __func__, ret);
254 return -EREMOTEIO;
255 }
256
257 /* signal_strength: rbuf[2-4] (24bit BE), use lower 16bit for now. */
258 *strength = (rbuf[3] << 8) + rbuf[4];
259 if (rbuf[2])
260 *strength = 0xffff;
261
262 return 0;
263}
264
265static int jdvbt90502_set_frontend(struct dvb_frontend *fe)
266{
267 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
268
269 /**
270 * NOTE: ignore all the parameters except frequency.
271 * others should be fixed to the proper value for ISDB-T,
272 * but don't check here.
273 */
274
275 struct jdvbt90502_state *state = fe->demodulator_priv;
276 int ret;
277
278 deb_fe("%s: Freq:%d\n", __func__, p->frequency);
279
280 /* This driver only works on auto mode */
281 p->inversion = INVERSION_AUTO;
282 p->bandwidth_hz = 6000000;
283 p->code_rate_HP = FEC_AUTO;
284 p->code_rate_LP = FEC_AUTO;
285 p->modulation = QAM_64;
286 p->transmission_mode = TRANSMISSION_MODE_AUTO;
287 p->guard_interval = GUARD_INTERVAL_AUTO;
288 p->hierarchy = HIERARCHY_AUTO;
289 p->delivery_system = SYS_ISDBT;
290
291 ret = jdvbt90502_pll_set_freq(state, p->frequency);
292 if (ret) {
293 deb_fe("%s:ret == %d\n", __func__, ret);
294 return -EREMOTEIO;
295 }
296
297 return 0;
298}
299
300
301/*
302 * (reg, val) commad list to initialize this module.
303 * captured on a Windows box.
304 */
305static u8 init_code[][2] = {
306 {0x01, 0x40},
307 {0x04, 0x38},
308 {0x05, 0x40},
309 {0x07, 0x40},
310 {0x0F, 0x4F},
311 {0x11, 0x21},
312 {0x12, 0x0B},
313 {0x13, 0x2F},
314 {0x14, 0x31},
315 {0x16, 0x02},
316 {0x21, 0xC4},
317 {0x22, 0x20},
318 {0x2C, 0x79},
319 {0x2D, 0x34},
320 {0x2F, 0x00},
321 {0x30, 0x28},
322 {0x31, 0x31},
323 {0x32, 0xDF},
324 {0x38, 0x01},
325 {0x39, 0x78},
326 {0x3B, 0x33},
327 {0x3C, 0x33},
328 {0x48, 0x90},
329 {0x51, 0x68},
330 {0x5E, 0x38},
331 {0x71, 0x00},
332 {0x72, 0x08},
333 {0x77, 0x00},
334 {0xC0, 0x21},
335 {0xC1, 0x10},
336 {0xE4, 0x1A},
337 {0xEA, 0x1F},
338 {0x77, 0x00},
339 {0x71, 0x00},
340 {0x71, 0x00},
341 {0x76, 0x0C},
342};
343
344static int jdvbt90502_init(struct dvb_frontend *fe)
345{
346 int i = -1;
347 int ret;
348 struct i2c_msg msg;
349
350 struct jdvbt90502_state *state = fe->demodulator_priv;
351
352 deb_fe("%s called.\n", __func__);
353
354 msg.addr = state->config.demod_address;
355 msg.flags = 0;
356 msg.len = 2;
357 for (i = 0; i < ARRAY_SIZE(init_code); i++) {
358 msg.buf = init_code[i];
359 ret = i2c_transfer(state->i2c, &msg, 1);
360 if (ret != 1)
361 goto error;
362 }
363 fe->dtv_property_cache.delivery_system = SYS_ISDBT;
364 msleep(100);
365
366 return 0;
367
368error:
369 deb_fe("%s: init_code[%d] failed. ret==%d\n", __func__, i, ret);
370 return -EREMOTEIO;
371}
372
373
374static void jdvbt90502_release(struct dvb_frontend *fe)
375{
376 struct jdvbt90502_state *state = fe->demodulator_priv;
377 kfree(state);
378}
379
380
381static const struct dvb_frontend_ops jdvbt90502_ops;
382
383struct dvb_frontend *jdvbt90502_attach(struct dvb_usb_device *d)
384{
385 struct jdvbt90502_state *state = NULL;
386
387 deb_info("%s called.\n", __func__);
388
389 /* allocate memory for the internal state */
390 state = kzalloc(sizeof(struct jdvbt90502_state), GFP_KERNEL);
391 if (state == NULL)
392 goto error;
393
394 /* setup the state */
395 state->i2c = &d->i2c_adap;
396 state->config = friio_fe_config;
397
398 /* create dvb_frontend */
399 state->frontend.ops = jdvbt90502_ops;
400 state->frontend.demodulator_priv = state;
401
402 if (jdvbt90502_init(&state->frontend) < 0)
403 goto error;
404
405 return &state->frontend;
406
407error:
408 kfree(state);
409 return NULL;
410}
411
412static const struct dvb_frontend_ops jdvbt90502_ops = {
413 .delsys = { SYS_ISDBT },
414 .info = {
415 .name = "Comtech JDVBT90502 ISDB-T",
416 .frequency_min_hz = 473000000, /* UHF 13ch, center */
417 .frequency_max_hz = 767142857, /* UHF 62ch, center */
418 .frequency_stepsize_hz = JDVBT90502_PLL_CLK / JDVBT90502_PLL_DIVIDER,
419
420 /* NOTE: this driver ignores all parameters but frequency. */
421 .caps = FE_CAN_INVERSION_AUTO |
422 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
423 FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
424 FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO |
425 FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
426 FE_CAN_TRANSMISSION_MODE_AUTO |
427 FE_CAN_GUARD_INTERVAL_AUTO |
428 FE_CAN_HIERARCHY_AUTO,
429 },
430
431 .release = jdvbt90502_release,
432
433 .init = jdvbt90502_init,
434 .write = _jdvbt90502_write,
435
436 .set_frontend = jdvbt90502_set_frontend,
437
438 .read_status = jdvbt90502_read_status,
439 .read_signal_strength = jdvbt90502_read_signal_strength,
440};
diff --git a/drivers/media/usb/dvb-usb/friio.c b/drivers/media/usb/dvb-usb/friio.c
deleted file mode 100644
index fe799a7ad44b..000000000000
--- a/drivers/media/usb/dvb-usb/friio.c
+++ /dev/null
@@ -1,522 +0,0 @@
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/media/dvb-drivers/dvb-usb.rst for more information
12 */
13#include "friio.h"
14
15/* debug */
16int dvb_usb_friio_debug;
17module_param_named(debug, dvb_usb_friio_debug, int, 0644);
18MODULE_PARM_DESC(debug,
19 "set debugging level (1=info,2=xfer,4=rc,8=fe (or-able))."
20 DVB_USB_DEBUG_STATUS);
21
22DVB_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 */
33static 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 */
62static 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 */
109static 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
140static u32 gl861_i2c_func(struct i2c_adapter *adapter)
141{
142 return I2C_FUNC_I2C;
143}
144
145static int friio_ext_ctl(struct dvb_usb_adapter *adap,
146 u32 sat_color, int lnb_on)
147{
148 int i;
149 int ret;
150 struct i2c_msg msg;
151 u8 *buf;
152 u32 mask;
153 u8 lnb = (lnb_on) ? FRIIO_CTL_LNB : 0;
154
155 buf = kmalloc(2, GFP_KERNEL);
156 if (!buf)
157 return -ENOMEM;
158
159 msg.addr = 0x00;
160 msg.flags = 0;
161 msg.len = 2;
162 msg.buf = buf;
163
164 buf[0] = 0x00;
165
166 /* send 2bit header (&B10) */
167 buf[1] = lnb | FRIIO_CTL_LED | FRIIO_CTL_STROBE;
168 ret = gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
169 buf[1] |= FRIIO_CTL_CLK;
170 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
171
172 buf[1] = lnb | FRIIO_CTL_STROBE;
173 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
174 buf[1] |= FRIIO_CTL_CLK;
175 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
176
177 /* send 32bit(satur, R, G, B) data in serial */
178 mask = 1 << 31;
179 for (i = 0; i < 32; i++) {
180 buf[1] = lnb | FRIIO_CTL_STROBE;
181 if (sat_color & mask)
182 buf[1] |= FRIIO_CTL_LED;
183 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
184 buf[1] |= FRIIO_CTL_CLK;
185 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
186 mask >>= 1;
187 }
188
189 /* set the strobe off */
190 buf[1] = lnb;
191 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
192 buf[1] |= FRIIO_CTL_CLK;
193 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
194
195 kfree(buf);
196 return (ret == 70);
197}
198
199
200static int friio_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff);
201
202/* TODO: move these init cmds to the FE's init routine? */
203static u8 streaming_init_cmds[][2] = {
204 {0x33, 0x08},
205 {0x37, 0x40},
206 {0x3A, 0x1F},
207 {0x3B, 0xFF},
208 {0x3C, 0x1F},
209 {0x3D, 0xFF},
210 {0x38, 0x00},
211 {0x35, 0x00},
212 {0x39, 0x00},
213 {0x36, 0x00},
214};
215static int cmdlen = sizeof(streaming_init_cmds) / 2;
216
217/*
218 * Command sequence in this init function is a replay
219 * of the captured USB commands from the Windows proprietary driver.
220 */
221static int friio_initialize(struct dvb_usb_device *d)
222{
223 int ret;
224 int i;
225 int retry = 0;
226 u8 *rbuf, *wbuf;
227
228 deb_info("%s called.\n", __func__);
229
230 wbuf = kmalloc(3, GFP_KERNEL);
231 if (!wbuf)
232 return -ENOMEM;
233
234 rbuf = kmalloc(2, GFP_KERNEL);
235 if (!rbuf) {
236 kfree(wbuf);
237 return -ENOMEM;
238 }
239
240 /* use gl861_i2c_msg instead of gl861_i2c_xfer(), */
241 /* because the i2c device is not set up yet. */
242 wbuf[0] = 0x11;
243 wbuf[1] = 0x02;
244 ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0);
245 if (ret < 0)
246 goto error;
247 msleep(2);
248
249 wbuf[0] = 0x11;
250 wbuf[1] = 0x00;
251 ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0);
252 if (ret < 0)
253 goto error;
254 msleep(1);
255
256 /* following msgs should be in the FE's init code? */
257 /* cmd sequence to identify the device type? (friio black/white) */
258 wbuf[0] = 0x03;
259 wbuf[1] = 0x80;
260 /* can't use gl861_i2c_cmd, as the register-addr is 16bit(0x0100) */
261 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
262 GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE,
263 0x1200, 0x0100, wbuf, 2, 2000);
264 if (ret < 0)
265 goto error;
266
267 msleep(2);
268 wbuf[0] = 0x00;
269 wbuf[2] = 0x01; /* reg.0x0100 */
270 wbuf[1] = 0x00;
271 ret = gl861_i2c_msg(d, 0x12 >> 1, wbuf, 3, rbuf, 2);
272 /* my Friio White returns 0xffff. */
273 if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff)
274 goto error;
275
276 msleep(2);
277 wbuf[0] = 0x03;
278 wbuf[1] = 0x80;
279 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
280 GL861_REQ_I2C_DATA_CTRL_WRITE, GL861_WRITE,
281 0x9000, 0x0100, wbuf, 2, 2000);
282 if (ret < 0)
283 goto error;
284
285 msleep(2);
286 wbuf[0] = 0x00;
287 wbuf[2] = 0x01; /* reg.0x0100 */
288 wbuf[1] = 0x00;
289 ret = gl861_i2c_msg(d, 0x90 >> 1, wbuf, 3, rbuf, 2);
290 /* my Friio White returns 0xffff again. */
291 if (ret < 0 || rbuf[0] != 0xff || rbuf[1] != 0xff)
292 goto error;
293
294 msleep(1);
295
296restart:
297 /* ============ start DEMOD init cmds ================== */
298 /* read PLL status to clear the POR bit */
299 wbuf[0] = JDVBT90502_2ND_I2C_REG;
300 wbuf[1] = (FRIIO_PLL_ADDR << 1) + 1; /* +1 for reading */
301 ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 2, NULL, 0);
302 if (ret < 0)
303 goto error;
304
305 msleep(5);
306 /* note: DEMODULATOR has 16bit register-address. */
307 wbuf[0] = 0x00;
308 wbuf[2] = 0x01; /* reg addr: 0x0100 */
309 wbuf[1] = 0x00; /* val: not used */
310 ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 3, rbuf, 1);
311 if (ret < 0)
312 goto error;
313/*
314 msleep(1);
315 wbuf[0] = 0x80;
316 wbuf[1] = 0x00;
317 ret = gl861_i2c_msg(d, FRIIO_DEMOD_ADDR, wbuf, 2, rbuf, 1);
318 if (ret < 0)
319 goto error;
320 */
321 if (rbuf[0] & 0x80) { /* still in PowerOnReset state? */
322 if (++retry > 3) {
323 deb_info("failed to get the correct FE demod status:0x%02x\n",
324 rbuf[0]);
325 goto error;
326 }
327 msleep(100);
328 goto restart;
329 }
330
331 /* TODO: check return value in rbuf */
332 /* =========== end DEMOD init cmds ===================== */
333 msleep(1);
334
335 wbuf[0] = 0x30;
336 wbuf[1] = 0x04;
337 ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0);
338 if (ret < 0)
339 goto error;
340
341 msleep(2);
342 /* following 2 cmds unnecessary? */
343 wbuf[0] = 0x00;
344 wbuf[1] = 0x01;
345 ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0);
346 if (ret < 0)
347 goto error;
348
349 wbuf[0] = 0x06;
350 wbuf[1] = 0x0F;
351 ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0);
352 if (ret < 0)
353 goto error;
354
355 /* some streaming ctl cmds (maybe) */
356 msleep(10);
357 for (i = 0; i < cmdlen; i++) {
358 ret = gl861_i2c_msg(d, 0x00, streaming_init_cmds[i], 2,
359 NULL, 0);
360 if (ret < 0)
361 goto error;
362 msleep(1);
363 }
364 msleep(20);
365
366 /* change the LED color etc. */
367 ret = friio_streaming_ctrl(&d->adapter[0], 0);
368 if (ret < 0)
369 goto error;
370
371 return 0;
372
373error:
374 kfree(wbuf);
375 kfree(rbuf);
376 deb_info("%s:ret == %d\n", __func__, ret);
377 return -EIO;
378}
379
380/* Callbacks for DVB USB */
381
382static int friio_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
383{
384 int ret;
385
386 deb_info("%s called.(%d)\n", __func__, onoff);
387
388 /* set the LED color and saturation (and LNB on) */
389 if (onoff)
390 ret = friio_ext_ctl(adap, 0x6400ff64, 1);
391 else
392 ret = friio_ext_ctl(adap, 0x96ff00ff, 1);
393
394 if (ret != 1) {
395 deb_info("%s failed to send cmdx. ret==%d\n", __func__, ret);
396 return -EREMOTEIO;
397 }
398 return 0;
399}
400
401static int friio_frontend_attach(struct dvb_usb_adapter *adap)
402{
403 if (friio_initialize(adap->dev) < 0)
404 return -EIO;
405
406 adap->fe_adap[0].fe = jdvbt90502_attach(adap->dev);
407 if (adap->fe_adap[0].fe == NULL)
408 return -EIO;
409
410 return 0;
411}
412
413/* DVB USB Driver stuff */
414static struct dvb_usb_device_properties friio_properties;
415
416static int friio_probe(struct usb_interface *intf,
417 const struct usb_device_id *id)
418{
419 struct dvb_usb_device *d;
420 struct usb_host_interface *alt;
421 int ret;
422
423 if (intf->num_altsetting < GL861_ALTSETTING_COUNT)
424 return -ENODEV;
425
426 alt = usb_altnum_to_altsetting(intf, FRIIO_BULK_ALTSETTING);
427 if (alt == NULL) {
428 deb_rc("not alt found!\n");
429 return -ENODEV;
430 }
431 ret = usb_set_interface(interface_to_usbdev(intf),
432 alt->desc.bInterfaceNumber,
433 alt->desc.bAlternateSetting);
434 if (ret != 0) {
435 deb_rc("failed to set alt-setting!\n");
436 return ret;
437 }
438
439 ret = dvb_usb_device_init(intf, &friio_properties,
440 THIS_MODULE, &d, adapter_nr);
441 if (ret == 0)
442 friio_streaming_ctrl(&d->adapter[0], 1);
443
444 return ret;
445}
446
447
448struct jdvbt90502_config friio_fe_config = {
449 .demod_address = FRIIO_DEMOD_ADDR,
450 .pll_address = FRIIO_PLL_ADDR,
451};
452
453static struct i2c_algorithm gl861_i2c_algo = {
454 .master_xfer = gl861_i2c_xfer,
455 .functionality = gl861_i2c_func,
456};
457
458static struct usb_device_id friio_table[] = {
459 { USB_DEVICE(USB_VID_774, USB_PID_FRIIO_WHITE) },
460 { } /* Terminating entry */
461};
462MODULE_DEVICE_TABLE(usb, friio_table);
463
464
465static struct dvb_usb_device_properties friio_properties = {
466 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
467 .usb_ctrl = DEVICE_SPECIFIC,
468
469 .size_of_priv = 0,
470
471 .num_adapters = 1,
472 .adapter = {
473 /* caps:0 => no pid filter, 188B TS packet */
474 /* GL861 has a HW pid filter, but no info available. */
475 {
476 .num_frontends = 1,
477 .fe = {{
478 .caps = 0,
479
480 .frontend_attach = friio_frontend_attach,
481 .streaming_ctrl = friio_streaming_ctrl,
482
483 .stream = {
484 .type = USB_BULK,
485 /* count <= MAX_NO_URBS_FOR_DATA_STREAM(10) */
486 .count = 8,
487 .endpoint = 0x01,
488 .u = {
489 /* GL861 has 6KB buf inside */
490 .bulk = {
491 .buffersize = 16384,
492 }
493 }
494 },
495 }},
496 }
497 },
498 .i2c_algo = &gl861_i2c_algo,
499
500 .num_device_descs = 1,
501 .devices = {
502 {
503 .name = "774 Friio ISDB-T USB2.0",
504 .cold_ids = { NULL },
505 .warm_ids = { &friio_table[0], NULL },
506 },
507 }
508};
509
510static struct usb_driver friio_driver = {
511 .name = "dvb_usb_friio",
512 .probe = friio_probe,
513 .disconnect = dvb_usb_device_exit,
514 .id_table = friio_table,
515};
516
517module_usb_driver(friio_driver);
518
519MODULE_AUTHOR("Akihiro Tsukada <tskd2@yahoo.co.jp>");
520MODULE_DESCRIPTION("Driver for Friio ISDB-T USB2.0 Receiver");
521MODULE_VERSION("0.2");
522MODULE_LICENSE("GPL");
diff --git a/drivers/media/usb/dvb-usb/friio.h b/drivers/media/usb/dvb-usb/friio.h
deleted file mode 100644
index a53af56d035c..000000000000
--- a/drivers/media/usb/dvb-usb/friio.h
+++ /dev/null
@@ -1,99 +0,0 @@
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/media/dvb-drivers/dvb-usb.rst 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) control: 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
33extern 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
92struct jdvbt90502_config {
93 u8 demod_address; /* i2c addr for demodulator IC */
94 u8 pll_address; /* PLL addr on the secondary i2c*/
95};
96extern struct jdvbt90502_config friio_fe_config;
97
98extern struct dvb_frontend *jdvbt90502_attach(struct dvb_usb_device *d);
99#endif