.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* DVB USB compliant linux driver for GL861 USB2.0 devices. |
---|
2 | 3 | * |
---|
3 | | - * This program is free software; you can redistribute it and/or modify it |
---|
4 | | - * under the terms of the GNU General Public License as published by the |
---|
5 | | - * Free Software Foundation, version 2. |
---|
6 | | - * |
---|
7 | | - * see Documentation/media/dvb-drivers/dvb-usb.rst for more information |
---|
| 4 | + * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information |
---|
8 | 5 | */ |
---|
9 | 6 | #include <linux/string.h> |
---|
10 | 7 | |
---|
11 | | -#include "gl861.h" |
---|
| 8 | +#include "dvb_usb.h" |
---|
12 | 9 | |
---|
13 | 10 | #include "zl10353.h" |
---|
14 | 11 | #include "qt1010.h" |
---|
.. | .. |
---|
17 | 14 | |
---|
18 | 15 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
---|
19 | 16 | |
---|
20 | | -static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, |
---|
21 | | - u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) |
---|
| 17 | +struct gl861 { |
---|
| 18 | + /* USB control message buffer */ |
---|
| 19 | + u8 buf[16]; |
---|
| 20 | + |
---|
| 21 | + struct i2c_adapter *demod_sub_i2c; |
---|
| 22 | + struct i2c_client *i2c_client_demod; |
---|
| 23 | + struct i2c_client *i2c_client_tuner; |
---|
| 24 | +}; |
---|
| 25 | + |
---|
| 26 | +#define CMD_WRITE_SHORT 0x01 |
---|
| 27 | +#define CMD_READ 0x02 |
---|
| 28 | +#define CMD_WRITE 0x03 |
---|
| 29 | + |
---|
| 30 | +static int gl861_ctrl_msg(struct dvb_usb_device *d, u8 request, u16 value, |
---|
| 31 | + u16 index, void *data, u16 size) |
---|
22 | 32 | { |
---|
23 | | - u16 index; |
---|
24 | | - u16 value = addr << (8 + 1); |
---|
25 | | - int wo = (rbuf == NULL || rlen == 0); /* write-only */ |
---|
26 | | - u8 req, type; |
---|
27 | | - u8 *buf; |
---|
| 33 | + struct gl861 *ctx = d_to_priv(d); |
---|
| 34 | + struct usb_interface *intf = d->intf; |
---|
28 | 35 | int ret; |
---|
| 36 | + unsigned int pipe; |
---|
| 37 | + u8 requesttype; |
---|
29 | 38 | |
---|
30 | | - if (wo) { |
---|
31 | | - req = GL861_REQ_I2C_WRITE; |
---|
32 | | - type = GL861_WRITE; |
---|
33 | | - buf = kmemdup(wbuf, wlen, GFP_KERNEL); |
---|
34 | | - } else { /* rw */ |
---|
35 | | - req = GL861_REQ_I2C_READ; |
---|
36 | | - type = GL861_READ; |
---|
37 | | - buf = kmalloc(rlen, GFP_KERNEL); |
---|
38 | | - } |
---|
39 | | - if (!buf) |
---|
40 | | - return -ENOMEM; |
---|
| 39 | + mutex_lock(&d->usb_mutex); |
---|
41 | 40 | |
---|
42 | | - switch (wlen) { |
---|
43 | | - case 1: |
---|
44 | | - index = wbuf[0]; |
---|
| 41 | + switch (request) { |
---|
| 42 | + case CMD_WRITE: |
---|
| 43 | + memcpy(ctx->buf, data, size); |
---|
| 44 | + fallthrough; |
---|
| 45 | + case CMD_WRITE_SHORT: |
---|
| 46 | + pipe = usb_sndctrlpipe(d->udev, 0); |
---|
| 47 | + requesttype = USB_TYPE_VENDOR | USB_DIR_OUT; |
---|
45 | 48 | break; |
---|
46 | | - case 2: |
---|
47 | | - index = wbuf[0]; |
---|
48 | | - value = value + wbuf[1]; |
---|
| 49 | + case CMD_READ: |
---|
| 50 | + pipe = usb_rcvctrlpipe(d->udev, 0); |
---|
| 51 | + requesttype = USB_TYPE_VENDOR | USB_DIR_IN; |
---|
49 | 52 | break; |
---|
50 | 53 | default: |
---|
51 | | - dev_err(&d->udev->dev, "%s: wlen=%d, aborting\n", |
---|
52 | | - KBUILD_MODNAME, wlen); |
---|
53 | | - kfree(buf); |
---|
54 | | - return -EINVAL; |
---|
| 54 | + ret = -EINVAL; |
---|
| 55 | + goto err_mutex_unlock; |
---|
55 | 56 | } |
---|
56 | 57 | |
---|
57 | | - usleep_range(1000, 2000); /* avoid I2C errors */ |
---|
| 58 | + ret = usb_control_msg(d->udev, pipe, request, requesttype, value, |
---|
| 59 | + index, ctx->buf, size, 200); |
---|
| 60 | + dev_dbg(&intf->dev, "%d | %02x %02x %*ph %*ph %*ph %s %*ph\n", |
---|
| 61 | + ret, requesttype, request, 2, &value, 2, &index, 2, &size, |
---|
| 62 | + (requesttype & USB_DIR_IN) ? "<<<" : ">>>", size, ctx->buf); |
---|
| 63 | + if (ret < 0) |
---|
| 64 | + goto err_mutex_unlock; |
---|
58 | 65 | |
---|
59 | | - ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type, |
---|
60 | | - value, index, buf, rlen, 2000); |
---|
| 66 | + if (request == CMD_READ) |
---|
| 67 | + memcpy(data, ctx->buf, size); |
---|
61 | 68 | |
---|
62 | | - if (!wo && ret > 0) |
---|
63 | | - memcpy(rbuf, buf, rlen); |
---|
| 69 | + usleep_range(1000, 2000); /* Avoid I2C errors */ |
---|
64 | 70 | |
---|
65 | | - kfree(buf); |
---|
| 71 | + mutex_unlock(&d->usb_mutex); |
---|
| 72 | + |
---|
| 73 | + return 0; |
---|
| 74 | + |
---|
| 75 | +err_mutex_unlock: |
---|
| 76 | + mutex_unlock(&d->usb_mutex); |
---|
| 77 | + dev_dbg(&intf->dev, "failed %d\n", ret); |
---|
66 | 78 | return ret; |
---|
67 | 79 | } |
---|
68 | 80 | |
---|
69 | | -/* I2C */ |
---|
70 | | -static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
---|
71 | | - int num) |
---|
| 81 | +static int gl861_short_write(struct dvb_usb_device *d, u8 addr, u8 reg, u8 val) |
---|
72 | 82 | { |
---|
73 | | - struct dvb_usb_device *d = i2c_get_adapdata(adap); |
---|
74 | | - int i; |
---|
75 | | - |
---|
76 | | - if (num > 2) |
---|
77 | | - return -EINVAL; |
---|
78 | | - |
---|
79 | | - if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
---|
80 | | - return -EAGAIN; |
---|
81 | | - |
---|
82 | | - for (i = 0; i < num; i++) { |
---|
83 | | - /* write/read request */ |
---|
84 | | - if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { |
---|
85 | | - if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf, |
---|
86 | | - msg[i].len, msg[i+1].buf, msg[i+1].len) < 0) |
---|
87 | | - break; |
---|
88 | | - i++; |
---|
89 | | - } else |
---|
90 | | - if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf, |
---|
91 | | - msg[i].len, NULL, 0) < 0) |
---|
92 | | - break; |
---|
93 | | - } |
---|
94 | | - |
---|
95 | | - mutex_unlock(&d->i2c_mutex); |
---|
96 | | - return i; |
---|
| 83 | + return gl861_ctrl_msg(d, CMD_WRITE_SHORT, |
---|
| 84 | + (addr << 9) | val, reg, NULL, 0); |
---|
97 | 85 | } |
---|
98 | 86 | |
---|
99 | | -static u32 gl861_i2c_func(struct i2c_adapter *adapter) |
---|
| 87 | +static int gl861_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
---|
| 88 | + int num) |
---|
| 89 | +{ |
---|
| 90 | + struct dvb_usb_device *d = i2c_get_adapdata(adap); |
---|
| 91 | + struct usb_interface *intf = d->intf; |
---|
| 92 | + struct gl861 *ctx = d_to_priv(d); |
---|
| 93 | + int ret; |
---|
| 94 | + u8 request, *data; |
---|
| 95 | + u16 value, index, size; |
---|
| 96 | + |
---|
| 97 | + /* XXX: I2C adapter maximum data lengths are not tested */ |
---|
| 98 | + if (num == 1 && !(msg[0].flags & I2C_M_RD)) { |
---|
| 99 | + /* I2C write */ |
---|
| 100 | + if (msg[0].len < 2 || msg[0].len > sizeof(ctx->buf)) { |
---|
| 101 | + ret = -EOPNOTSUPP; |
---|
| 102 | + goto err; |
---|
| 103 | + } |
---|
| 104 | + |
---|
| 105 | + value = (msg[0].addr << 1) << 8; |
---|
| 106 | + index = msg[0].buf[0]; |
---|
| 107 | + |
---|
| 108 | + if (msg[0].len == 2) { |
---|
| 109 | + request = CMD_WRITE_SHORT; |
---|
| 110 | + value |= msg[0].buf[1]; |
---|
| 111 | + size = 0; |
---|
| 112 | + data = NULL; |
---|
| 113 | + } else { |
---|
| 114 | + request = CMD_WRITE; |
---|
| 115 | + size = msg[0].len - 1; |
---|
| 116 | + data = &msg[0].buf[1]; |
---|
| 117 | + } |
---|
| 118 | + |
---|
| 119 | + ret = gl861_ctrl_msg(d, request, value, index, data, size); |
---|
| 120 | + } else if (num == 2 && !(msg[0].flags & I2C_M_RD) && |
---|
| 121 | + (msg[1].flags & I2C_M_RD)) { |
---|
| 122 | + /* I2C write + read */ |
---|
| 123 | + if (msg[0].len != 1 || msg[1].len > sizeof(ctx->buf)) { |
---|
| 124 | + ret = -EOPNOTSUPP; |
---|
| 125 | + goto err; |
---|
| 126 | + } |
---|
| 127 | + |
---|
| 128 | + value = (msg[0].addr << 1) << 8; |
---|
| 129 | + index = msg[0].buf[0]; |
---|
| 130 | + request = CMD_READ; |
---|
| 131 | + |
---|
| 132 | + ret = gl861_ctrl_msg(d, request, value, index, |
---|
| 133 | + msg[1].buf, msg[1].len); |
---|
| 134 | + } else if (num == 1 && (msg[0].flags & I2C_M_RD)) { |
---|
| 135 | + /* I2C read */ |
---|
| 136 | + if (msg[0].len > sizeof(ctx->buf)) { |
---|
| 137 | + ret = -EOPNOTSUPP; |
---|
| 138 | + goto err; |
---|
| 139 | + } |
---|
| 140 | + value = (msg[0].addr << 1) << 8; |
---|
| 141 | + index = 0x0100; |
---|
| 142 | + request = CMD_READ; |
---|
| 143 | + |
---|
| 144 | + ret = gl861_ctrl_msg(d, request, value, index, |
---|
| 145 | + msg[0].buf, msg[0].len); |
---|
| 146 | + } else { |
---|
| 147 | + /* Unsupported I2C message */ |
---|
| 148 | + dev_dbg(&intf->dev, "unknown i2c msg, num %u\n", num); |
---|
| 149 | + ret = -EOPNOTSUPP; |
---|
| 150 | + } |
---|
| 151 | + if (ret) |
---|
| 152 | + goto err; |
---|
| 153 | + |
---|
| 154 | + return num; |
---|
| 155 | +err: |
---|
| 156 | + dev_dbg(&intf->dev, "failed %d\n", ret); |
---|
| 157 | + return ret; |
---|
| 158 | +} |
---|
| 159 | + |
---|
| 160 | +static u32 gl861_i2c_functionality(struct i2c_adapter *adapter) |
---|
100 | 161 | { |
---|
101 | 162 | return I2C_FUNC_I2C; |
---|
102 | 163 | } |
---|
103 | 164 | |
---|
104 | 165 | static struct i2c_algorithm gl861_i2c_algo = { |
---|
105 | | - .master_xfer = gl861_i2c_xfer, |
---|
106 | | - .functionality = gl861_i2c_func, |
---|
| 166 | + .master_xfer = gl861_i2c_master_xfer, |
---|
| 167 | + .functionality = gl861_i2c_functionality, |
---|
107 | 168 | }; |
---|
108 | 169 | |
---|
109 | 170 | /* Callbacks for DVB USB */ |
---|
.. | .. |
---|
152 | 213 | .owner = THIS_MODULE, |
---|
153 | 214 | .adapter_nr = adapter_nr, |
---|
154 | 215 | |
---|
| 216 | + .size_of_priv = sizeof(struct gl861), |
---|
| 217 | + |
---|
155 | 218 | .i2c_algo = &gl861_i2c_algo, |
---|
156 | 219 | .frontend_attach = gl861_frontend_attach, |
---|
157 | 220 | .tuner_attach = gl861_tuner_attach, |
---|
.. | .. |
---|
169 | 232 | /* |
---|
170 | 233 | * For Friio |
---|
171 | 234 | */ |
---|
172 | | - |
---|
173 | | -struct friio_priv { |
---|
174 | | - struct i2c_adapter *demod_sub_i2c; |
---|
175 | | - struct i2c_client *i2c_client_demod; |
---|
176 | | - struct i2c_client *i2c_client_tuner; |
---|
177 | | - struct i2c_adapter tuner_adap; |
---|
178 | | -}; |
---|
179 | | - |
---|
180 | 235 | struct friio_config { |
---|
181 | 236 | struct i2c_board_info demod_info; |
---|
182 | 237 | struct tc90522_config demod_cfg; |
---|
.. | .. |
---|
187 | 242 | |
---|
188 | 243 | static const struct friio_config friio_config = { |
---|
189 | 244 | .demod_info = { I2C_BOARD_INFO(TC90522_I2C_DEV_TER, 0x18), }, |
---|
| 245 | + .demod_cfg = { .split_tuner_read_i2c = true, }, |
---|
190 | 246 | .tuner_info = { I2C_BOARD_INFO("tua6034_friio", 0x60), }, |
---|
191 | 247 | }; |
---|
192 | 248 | |
---|
193 | | -/* For another type of I2C: |
---|
194 | | - * message sent by a USB control-read/write transaction with data stage. |
---|
195 | | - * Used in init/config of Friio. |
---|
196 | | - */ |
---|
197 | | -static int |
---|
198 | | -gl861_i2c_write_ex(struct dvb_usb_device *d, u8 addr, u8 *wbuf, u16 wlen) |
---|
199 | | -{ |
---|
200 | | - u8 *buf; |
---|
201 | | - int ret; |
---|
202 | | - |
---|
203 | | - buf = kmalloc(wlen, GFP_KERNEL); |
---|
204 | | - if (!buf) |
---|
205 | | - return -ENOMEM; |
---|
206 | | - |
---|
207 | | - memcpy(buf, wbuf, wlen); |
---|
208 | | - ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), |
---|
209 | | - GL861_REQ_I2C_RAW, GL861_WRITE, |
---|
210 | | - addr << (8 + 1), 0x0100, buf, wlen, 2000); |
---|
211 | | - kfree(buf); |
---|
212 | | - return ret; |
---|
213 | | -} |
---|
214 | | - |
---|
215 | | -static int |
---|
216 | | -gl861_i2c_read_ex(struct dvb_usb_device *d, u8 addr, u8 *rbuf, u16 rlen) |
---|
217 | | -{ |
---|
218 | | - u8 *buf; |
---|
219 | | - int ret; |
---|
220 | | - |
---|
221 | | - buf = kmalloc(rlen, GFP_KERNEL); |
---|
222 | | - if (!buf) |
---|
223 | | - return -ENOMEM; |
---|
224 | | - |
---|
225 | | - ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), |
---|
226 | | - GL861_REQ_I2C_READ, GL861_READ, |
---|
227 | | - addr << (8 + 1), 0x0100, buf, rlen, 2000); |
---|
228 | | - if (ret > 0 && rlen > 0) |
---|
229 | | - memcpy(buf, rbuf, rlen); |
---|
230 | | - kfree(buf); |
---|
231 | | - return ret; |
---|
232 | | -} |
---|
233 | | - |
---|
234 | | -/* For I2C transactions to the tuner of Friio (dvb_pll). |
---|
235 | | - * |
---|
236 | | - * Friio uses irregular USB encapsulation for tuner i2c transactions: |
---|
237 | | - * write transacions are encapsulated with a different USB 'request' value. |
---|
238 | | - * |
---|
239 | | - * Although all transactions are sent via the demod(tc90522) |
---|
240 | | - * and the demod provides an i2c adapter for them, it cannot be used in Friio |
---|
241 | | - * since it assumes using the same parent adapter with the demod, |
---|
242 | | - * which does not use the request value and uses same one for both read/write. |
---|
243 | | - * So we define a dedicated i2c adapter here. |
---|
244 | | - */ |
---|
245 | | - |
---|
246 | | -static int |
---|
247 | | -friio_i2c_tuner_read(struct dvb_usb_device *d, struct i2c_msg *msg) |
---|
248 | | -{ |
---|
249 | | - struct friio_priv *priv; |
---|
250 | | - u8 addr; |
---|
251 | | - |
---|
252 | | - priv = d_to_priv(d); |
---|
253 | | - addr = priv->i2c_client_demod->addr; |
---|
254 | | - return gl861_i2c_read_ex(d, addr, msg->buf, msg->len); |
---|
255 | | -} |
---|
256 | | - |
---|
257 | | -static int |
---|
258 | | -friio_i2c_tuner_write(struct dvb_usb_device *d, struct i2c_msg *msg) |
---|
259 | | -{ |
---|
260 | | - u8 *buf; |
---|
261 | | - int ret; |
---|
262 | | - struct friio_priv *priv; |
---|
263 | | - |
---|
264 | | - priv = d_to_priv(d); |
---|
265 | | - |
---|
266 | | - if (msg->len < 1) |
---|
267 | | - return -EINVAL; |
---|
268 | | - |
---|
269 | | - buf = kmalloc(msg->len + 1, GFP_KERNEL); |
---|
270 | | - if (!buf) |
---|
271 | | - return -ENOMEM; |
---|
272 | | - buf[0] = msg->addr << 1; |
---|
273 | | - memcpy(buf + 1, msg->buf, msg->len); |
---|
274 | | - |
---|
275 | | - ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0), |
---|
276 | | - GL861_REQ_I2C_RAW, GL861_WRITE, |
---|
277 | | - priv->i2c_client_demod->addr << (8 + 1), |
---|
278 | | - 0xFE, buf, msg->len + 1, 2000); |
---|
279 | | - kfree(buf); |
---|
280 | | - return ret; |
---|
281 | | -} |
---|
282 | | - |
---|
283 | | -static int friio_tuner_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
---|
284 | | - int num) |
---|
285 | | -{ |
---|
286 | | - struct dvb_usb_device *d = i2c_get_adapdata(adap); |
---|
287 | | - int i; |
---|
288 | | - |
---|
289 | | - if (num > 2) |
---|
290 | | - return -EINVAL; |
---|
291 | | - |
---|
292 | | - if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
---|
293 | | - return -EAGAIN; |
---|
294 | | - |
---|
295 | | - for (i = 0; i < num; i++) { |
---|
296 | | - int ret; |
---|
297 | | - |
---|
298 | | - if (msg[i].flags & I2C_M_RD) |
---|
299 | | - ret = friio_i2c_tuner_read(d, &msg[i]); |
---|
300 | | - else |
---|
301 | | - ret = friio_i2c_tuner_write(d, &msg[i]); |
---|
302 | | - |
---|
303 | | - if (ret < 0) |
---|
304 | | - break; |
---|
305 | | - |
---|
306 | | - usleep_range(1000, 2000); /* avoid I2C errors */ |
---|
307 | | - } |
---|
308 | | - |
---|
309 | | - mutex_unlock(&d->i2c_mutex); |
---|
310 | | - return i; |
---|
311 | | -} |
---|
312 | | - |
---|
313 | | -static struct i2c_algorithm friio_tuner_i2c_algo = { |
---|
314 | | - .master_xfer = friio_tuner_i2c_xfer, |
---|
315 | | - .functionality = gl861_i2c_func, |
---|
316 | | -}; |
---|
317 | 249 | |
---|
318 | 250 | /* GPIO control in Friio */ |
---|
319 | 251 | |
---|
.. | .. |
---|
357 | 289 | ret += i2c_transfer(&d->i2c_adap, &msg, 1); |
---|
358 | 290 | |
---|
359 | 291 | /* send 32bit(satur, R, G, B) data in serial */ |
---|
360 | | - mask = 1 << 31; |
---|
| 292 | + mask = 1UL << 31; |
---|
361 | 293 | for (i = 0; i < 32; i++) { |
---|
362 | 294 | buf[1] = power | FRIIO_CTL_STROBE; |
---|
363 | 295 | if (sat_color & mask) |
---|
.. | .. |
---|
381 | 313 | /* init/config of gl861 for Friio */ |
---|
382 | 314 | /* NOTE: |
---|
383 | 315 | * This function cannot be moved to friio_init()/dvb_usbv2_init(), |
---|
384 | | - * because the init defined here must be done before any activities like I2C, |
---|
| 316 | + * because the init defined here includes a whole device reset, |
---|
| 317 | + * it must be run early before any activities like I2C, |
---|
385 | 318 | * but friio_init() is called by dvb-usbv2 after {_frontend, _tuner}_attach(), |
---|
386 | 319 | * where I2C communication is used. |
---|
| 320 | + * In addition, this reset is required in reset_resume() as well. |
---|
387 | 321 | * Thus this function is set to be called from _power_ctl(). |
---|
388 | 322 | * |
---|
389 | 323 | * Since it will be called on the early init stage |
---|
.. | .. |
---|
393 | 327 | static int friio_reset(struct dvb_usb_device *d) |
---|
394 | 328 | { |
---|
395 | 329 | int i, ret; |
---|
396 | | - u8 wbuf[2], rbuf[2]; |
---|
| 330 | + u8 wbuf[1], rbuf[2]; |
---|
397 | 331 | |
---|
398 | 332 | static const u8 friio_init_cmds[][2] = { |
---|
399 | 333 | {0x33, 0x08}, {0x37, 0x40}, {0x3a, 0x1f}, {0x3b, 0xff}, |
---|
.. | .. |
---|
405 | 339 | if (ret < 0) |
---|
406 | 340 | return ret; |
---|
407 | 341 | |
---|
408 | | - wbuf[0] = 0x11; |
---|
409 | | - wbuf[1] = 0x02; |
---|
410 | | - ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); |
---|
| 342 | + ret = gl861_short_write(d, 0x00, 0x11, 0x02); |
---|
411 | 343 | if (ret < 0) |
---|
412 | 344 | return ret; |
---|
413 | 345 | usleep_range(2000, 3000); |
---|
414 | 346 | |
---|
415 | | - wbuf[0] = 0x11; |
---|
416 | | - wbuf[1] = 0x00; |
---|
417 | | - ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); |
---|
| 347 | + ret = gl861_short_write(d, 0x00, 0x11, 0x00); |
---|
418 | 348 | if (ret < 0) |
---|
419 | 349 | return ret; |
---|
420 | 350 | |
---|
.. | .. |
---|
424 | 354 | */ |
---|
425 | 355 | |
---|
426 | 356 | usleep_range(1000, 2000); |
---|
427 | | - wbuf[0] = 0x03; |
---|
428 | | - wbuf[1] = 0x80; |
---|
429 | | - ret = gl861_i2c_write_ex(d, 0x09, wbuf, 2); |
---|
| 357 | + wbuf[0] = 0x80; |
---|
| 358 | + ret = gl861_ctrl_msg(d, CMD_WRITE, 0x09 << 9, 0x03, wbuf, 1); |
---|
430 | 359 | if (ret < 0) |
---|
431 | 360 | return ret; |
---|
432 | 361 | |
---|
433 | 362 | usleep_range(2000, 3000); |
---|
434 | | - ret = gl861_i2c_read_ex(d, 0x09, rbuf, 2); |
---|
| 363 | + ret = gl861_ctrl_msg(d, CMD_READ, 0x09 << 9, 0x0100, rbuf, 2); |
---|
435 | 364 | if (ret < 0) |
---|
436 | 365 | return ret; |
---|
437 | 366 | if (rbuf[0] != 0xff || rbuf[1] != 0xff) |
---|
.. | .. |
---|
439 | 368 | |
---|
440 | 369 | |
---|
441 | 370 | usleep_range(1000, 2000); |
---|
442 | | - ret = gl861_i2c_write_ex(d, 0x48, wbuf, 2); |
---|
| 371 | + wbuf[0] = 0x80; |
---|
| 372 | + ret = gl861_ctrl_msg(d, CMD_WRITE, 0x48 << 9, 0x03, wbuf, 1); |
---|
443 | 373 | if (ret < 0) |
---|
444 | 374 | return ret; |
---|
445 | 375 | |
---|
446 | 376 | usleep_range(2000, 3000); |
---|
447 | | - ret = gl861_i2c_read_ex(d, 0x48, rbuf, 2); |
---|
| 377 | + ret = gl861_ctrl_msg(d, CMD_READ, 0x48 << 9, 0x0100, rbuf, 2); |
---|
448 | 378 | if (ret < 0) |
---|
449 | 379 | return ret; |
---|
450 | 380 | if (rbuf[0] != 0xff || rbuf[1] != 0xff) |
---|
451 | 381 | return -ENODEV; |
---|
452 | 382 | |
---|
453 | | - wbuf[0] = 0x30; |
---|
454 | | - wbuf[1] = 0x04; |
---|
455 | | - ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); |
---|
| 383 | + ret = gl861_short_write(d, 0x00, 0x30, 0x04); |
---|
456 | 384 | if (ret < 0) |
---|
457 | 385 | return ret; |
---|
458 | 386 | |
---|
459 | | - wbuf[0] = 0x00; |
---|
460 | | - wbuf[1] = 0x01; |
---|
461 | | - ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); |
---|
| 387 | + ret = gl861_short_write(d, 0x00, 0x00, 0x01); |
---|
462 | 388 | if (ret < 0) |
---|
463 | 389 | return ret; |
---|
464 | 390 | |
---|
465 | | - wbuf[0] = 0x06; |
---|
466 | | - wbuf[1] = 0x0f; |
---|
467 | | - ret = gl861_i2c_msg(d, 0x00, wbuf, 2, NULL, 0); |
---|
| 391 | + ret = gl861_short_write(d, 0x00, 0x06, 0x0f); |
---|
468 | 392 | if (ret < 0) |
---|
469 | 393 | return ret; |
---|
470 | 394 | |
---|
471 | 395 | for (i = 0; i < ARRAY_SIZE(friio_init_cmds); i++) { |
---|
472 | | - ret = gl861_i2c_msg(d, 0x00, (u8 *)friio_init_cmds[i], 2, |
---|
473 | | - NULL, 0); |
---|
| 396 | + ret = gl861_short_write(d, 0x00, friio_init_cmds[i][0], |
---|
| 397 | + friio_init_cmds[i][1]); |
---|
474 | 398 | if (ret < 0) |
---|
475 | 399 | return ret; |
---|
476 | 400 | } |
---|
.. | .. |
---|
492 | 416 | struct dvb_usb_device *d; |
---|
493 | 417 | struct tc90522_config cfg; |
---|
494 | 418 | struct i2c_client *cl; |
---|
495 | | - struct friio_priv *priv; |
---|
| 419 | + struct gl861 *priv; |
---|
496 | 420 | |
---|
497 | 421 | info = &friio_config.demod_info; |
---|
| 422 | + cfg = friio_config.demod_cfg; |
---|
498 | 423 | d = adap_to_d(adap); |
---|
499 | 424 | cl = dvb_module_probe("tc90522", info->type, |
---|
500 | 425 | &d->i2c_adap, info->addr, &cfg); |
---|
.. | .. |
---|
502 | 427 | return -ENODEV; |
---|
503 | 428 | adap->fe[0] = cfg.fe; |
---|
504 | 429 | |
---|
505 | | - /* ignore cfg.tuner_i2c and create new one */ |
---|
506 | 430 | priv = adap_to_priv(adap); |
---|
507 | 431 | priv->i2c_client_demod = cl; |
---|
508 | | - priv->tuner_adap.algo = &friio_tuner_i2c_algo; |
---|
509 | | - priv->tuner_adap.dev.parent = &d->udev->dev; |
---|
510 | | - strlcpy(priv->tuner_adap.name, d->name, sizeof(priv->tuner_adap.name)); |
---|
511 | | - strlcat(priv->tuner_adap.name, "-tuner", sizeof(priv->tuner_adap.name)); |
---|
512 | | - priv->demod_sub_i2c = &priv->tuner_adap; |
---|
513 | | - i2c_set_adapdata(&priv->tuner_adap, d); |
---|
514 | | - |
---|
515 | | - return i2c_add_adapter(&priv->tuner_adap); |
---|
| 432 | + priv->demod_sub_i2c = cfg.tuner_i2c; |
---|
| 433 | + return 0; |
---|
516 | 434 | } |
---|
517 | 435 | |
---|
518 | 436 | static int friio_frontend_detach(struct dvb_usb_adapter *adap) |
---|
519 | 437 | { |
---|
520 | | - struct friio_priv *priv; |
---|
| 438 | + struct gl861 *priv; |
---|
521 | 439 | |
---|
522 | 440 | priv = adap_to_priv(adap); |
---|
523 | | - i2c_del_adapter(&priv->tuner_adap); |
---|
524 | 441 | dvb_module_release(priv->i2c_client_demod); |
---|
525 | 442 | return 0; |
---|
526 | 443 | } |
---|
.. | .. |
---|
530 | 447 | const struct i2c_board_info *info; |
---|
531 | 448 | struct dvb_pll_config cfg; |
---|
532 | 449 | struct i2c_client *cl; |
---|
533 | | - struct friio_priv *priv; |
---|
| 450 | + struct gl861 *priv; |
---|
534 | 451 | |
---|
535 | 452 | priv = adap_to_priv(adap); |
---|
536 | 453 | info = &friio_config.tuner_info; |
---|
.. | .. |
---|
547 | 464 | |
---|
548 | 465 | static int friio_tuner_detach(struct dvb_usb_adapter *adap) |
---|
549 | 466 | { |
---|
550 | | - struct friio_priv *priv; |
---|
| 467 | + struct gl861 *priv; |
---|
551 | 468 | |
---|
552 | 469 | priv = adap_to_priv(adap); |
---|
553 | 470 | dvb_module_release(priv->i2c_client_tuner); |
---|
.. | .. |
---|
558 | 475 | { |
---|
559 | 476 | int i; |
---|
560 | 477 | int ret; |
---|
561 | | - struct friio_priv *priv; |
---|
| 478 | + struct gl861 *priv; |
---|
562 | 479 | |
---|
563 | 480 | static const u8 demod_init[][2] = { |
---|
564 | 481 | {0x01, 0x40}, {0x04, 0x38}, {0x05, 0x40}, {0x07, 0x40}, |
---|
.. | .. |
---|
610 | 527 | .owner = THIS_MODULE, |
---|
611 | 528 | .adapter_nr = adapter_nr, |
---|
612 | 529 | |
---|
613 | | - .size_of_priv = sizeof(struct friio_priv), |
---|
| 530 | + .size_of_priv = sizeof(struct gl861), |
---|
614 | 531 | |
---|
615 | 532 | .i2c_algo = &gl861_i2c_algo, |
---|
616 | 533 | .power_ctrl = friio_power_ctrl, |
---|
.. | .. |
---|
633 | 550 | static const struct usb_device_id gl861_id_table[] = { |
---|
634 | 551 | { DVB_USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801, |
---|
635 | 552 | &gl861_props, "MSI Mega Sky 55801 DVB-T USB2.0", NULL) }, |
---|
636 | | - { DVB_USB_DEVICE(USB_VID_ALINK, USB_VID_ALINK_DTU, |
---|
| 553 | + { DVB_USB_DEVICE(USB_VID_ALINK, USB_PID_ALINK_DTU, |
---|
637 | 554 | &gl861_props, "A-LINK DTU DVB-T USB2.0", NULL) }, |
---|
638 | 555 | { DVB_USB_DEVICE(USB_VID_774, USB_PID_FRIIO_WHITE, |
---|
639 | 556 | &friio_props, "774 Friio White ISDB-T USB2.0", NULL) }, |
---|