1 // SPDX-License-Identifier: GPL-2.0-only
2 /* DVB USB compliant Linux driver for the
3 * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
8 * Thanks to GENPIX for the sample code used to implement this module.
10 * This module is based off the vp7045 and vp702x modules
12 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
15 #include "gp8psk-fe.h"
18 static char bcm4500_firmware[] = "dvb-usb-gp8psk-02.fw";
19 int dvb_usb_gp8psk_debug;
20 module_param_named(debug,dvb_usb_gp8psk_debug, int, 0644);
21 MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
23 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
26 unsigned char data[80];
29 static int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value,
30 u16 index, u8 *b, int blen)
32 struct gp8psk_state *st = d->priv;
35 if (blen > sizeof(st->data))
38 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
41 while (ret >= 0 && ret != blen && try < 3) {
42 ret = usb_control_msg(d->udev,
43 usb_rcvctrlpipe(d->udev,0),
45 USB_TYPE_VENDOR | USB_DIR_IN,
46 value, index, st->data, blen,
48 deb_info("reading number %d (ret: %d)\n",try,ret);
52 if (ret < 0 || ret != blen) {
53 warn("usb in %d operation failed.", req);
57 memcpy(b, st->data, blen);
60 deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
61 debug_dump(b,blen,deb_xfer);
63 mutex_unlock(&d->usb_mutex);
68 static int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
69 u16 index, u8 *b, int blen)
71 struct gp8psk_state *st = d->priv;
74 deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
75 debug_dump(b,blen,deb_xfer);
77 if (blen > sizeof(st->data))
80 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
83 memcpy(st->data, b, blen);
84 if (usb_control_msg(d->udev,
85 usb_sndctrlpipe(d->udev,0),
87 USB_TYPE_VENDOR | USB_DIR_OUT,
88 value, index, st->data, blen,
90 warn("usb out operation failed.");
94 mutex_unlock(&d->usb_mutex);
100 static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
102 return gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6);
105 static int gp8psk_get_fpga_version(struct dvb_usb_device *d, u8 *fpga_vers)
107 return gp8psk_usb_in_op(d, GET_FPGA_VERS, 0, 0, fpga_vers, 1);
110 static void gp8psk_info(struct dvb_usb_device *d)
112 u8 fpga_vers, fw_vers[6];
114 if (!gp8psk_get_fw_version(d, fw_vers))
115 info("FW Version = %i.%02i.%i (0x%x) Build %4i/%02i/%02i",
116 fw_vers[2], fw_vers[1], fw_vers[0], GP8PSK_FW_VERS(fw_vers),
117 2000 + fw_vers[5], fw_vers[4], fw_vers[3]);
119 info("failed to get FW version");
121 if (!gp8psk_get_fpga_version(d, &fpga_vers))
122 info("FPGA Version = %i", fpga_vers);
124 info("failed to get FPGA version");
127 static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
130 const struct firmware *fw = NULL;
133 if ((ret = request_firmware(&fw, bcm4500_firmware,
134 &d->udev->dev)) != 0) {
135 err("did not find the bcm4500 firmware file '%s' (status %d). You can use <kernel_dir>/scripts/get_dvb_firmware to get the firmware",
136 bcm4500_firmware,ret);
142 if (gp8psk_usb_out_op(d, LOAD_BCM4500,1,0,NULL, 0))
145 info("downloading bcm4500 firmware from file '%s'",bcm4500_firmware);
148 buf = kmalloc(64, GFP_KERNEL);
154 while (ptr[0] != 0xff) {
155 u16 buflen = ptr[0] + 4;
156 if (ptr + buflen >= fw->data + fw->size) {
157 err("failed to load bcm4500 firmware.");
161 err("firmware chunk size bigger than 64 bytes.");
165 memcpy(buf, ptr, buflen);
166 if (dvb_usb_generic_write(d, buf, buflen)) {
167 err("failed to load bcm4500 firmware.");
178 release_firmware(fw);
183 static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
186 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
189 gp8psk_usb_in_op(d, GET_8PSK_CONFIG,0,0,&status,1);
190 if (! (status & bm8pskStarted)) { /* started */
191 if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
192 gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0);
193 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
198 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
199 if (! (status & bm8pskFW_Loaded)) /* BCM4500 firmware loaded */
200 if(gp8psk_load_bcm4500fw(d))
203 if (! (status & bmIntersilOn)) /* LNB Power */
204 if (gp8psk_usb_in_op(d, START_INTERSIL, 1, 0,
208 /* Set DVB mode to 1 */
209 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
210 if (gp8psk_usb_out_op(d, SET_DVB_MODE, 1, 0, NULL, 0))
212 /* Abort possible TS (if previous tune crashed) */
213 if (gp8psk_usb_out_op(d, ARM_TRANSFER, 0, 0, NULL, 0))
216 /* Turn off LNB power */
217 if (gp8psk_usb_in_op(d, START_INTERSIL, 0, 0, &buf, 1))
219 /* Turn off 8psk power */
220 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
222 if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
223 gp8psk_usb_out_op(d, CW3K_INIT, 0, 0, NULL, 0);
228 static int gp8psk_bcm4500_reload(struct dvb_usb_device *d)
231 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
233 deb_xfer("reloading firmware\n");
235 /* Turn off 8psk power */
236 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
238 /* Turn On 8psk power */
239 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
241 /* load BCM4500 firmware */
242 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
243 if (gp8psk_load_bcm4500fw(d))
248 static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
250 return gp8psk_usb_out_op(adap->dev, ARM_TRANSFER, onoff, 0 , NULL, 0);
253 /* Callbacks for gp8psk-fe.c */
255 static int gp8psk_fe_in(void *priv, u8 req, u16 value,
256 u16 index, u8 *b, int blen)
258 struct dvb_usb_device *d = priv;
260 return gp8psk_usb_in_op(d, req, value, index, b, blen);
263 static int gp8psk_fe_out(void *priv, u8 req, u16 value,
264 u16 index, u8 *b, int blen)
266 struct dvb_usb_device *d = priv;
268 return gp8psk_usb_out_op(d, req, value, index, b, blen);
271 static int gp8psk_fe_reload(void *priv)
273 struct dvb_usb_device *d = priv;
275 return gp8psk_bcm4500_reload(d);
278 static const struct gp8psk_fe_ops gp8psk_fe_ops = {
280 .out = gp8psk_fe_out,
281 .reload = gp8psk_fe_reload,
284 static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap)
286 struct dvb_usb_device *d = adap->dev;
287 int id = le16_to_cpu(d->udev->descriptor.idProduct);
290 is_rev1 = (id == USB_PID_GENPIX_8PSK_REV_1_WARM) ? true : false;
292 adap->fe_adap[0].fe = dvb_attach(gp8psk_fe_attach,
293 &gp8psk_fe_ops, d, is_rev1);
297 static struct dvb_usb_device_properties gp8psk_properties;
299 static int gp8psk_usb_probe(struct usb_interface *intf,
300 const struct usb_device_id *id)
303 struct usb_device *udev = interface_to_usbdev(intf);
304 ret = dvb_usb_device_init(intf, &gp8psk_properties,
305 THIS_MODULE, NULL, adapter_nr);
307 info("found Genpix USB device pID = %x (hex)",
308 le16_to_cpu(udev->descriptor.idProduct));
314 GENPIX_8PSK_REV_1_COLD,
315 GENPIX_8PSK_REV_1_WARM,
319 GENPIX_SKYWALKER_CW3K,
322 static struct usb_device_id gp8psk_usb_table[] = {
323 DVB_USB_DEV(GENPIX, GENPIX_8PSK_REV_1_COLD),
324 DVB_USB_DEV(GENPIX, GENPIX_8PSK_REV_1_WARM),
325 DVB_USB_DEV(GENPIX, GENPIX_8PSK_REV_2),
326 DVB_USB_DEV(GENPIX, GENPIX_SKYWALKER_1),
327 DVB_USB_DEV(GENPIX, GENPIX_SKYWALKER_2),
328 DVB_USB_DEV(GENPIX, GENPIX_SKYWALKER_CW3K),
332 MODULE_DEVICE_TABLE(usb, gp8psk_usb_table);
334 static struct dvb_usb_device_properties gp8psk_properties = {
335 .usb_ctrl = CYPRESS_FX2,
336 .firmware = "dvb-usb-gp8psk-01.fw",
338 .size_of_priv = sizeof(struct gp8psk_state),
345 .streaming_ctrl = gp8psk_streaming_ctrl,
346 .frontend_attach = gp8psk_frontend_attach,
347 /* parameter for the MPEG2-data transfer */
361 .power_ctrl = gp8psk_power_ctrl,
363 .generic_bulk_ctrl_endpoint = 0x01,
365 .num_device_descs = 4,
367 { .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver",
368 .cold_ids = { &gp8psk_usb_table[GENPIX_8PSK_REV_1_COLD], NULL },
369 .warm_ids = { &gp8psk_usb_table[GENPIX_8PSK_REV_1_WARM], NULL },
371 { .name = "Genpix 8PSK-to-USB2 Rev.2 DVB-S receiver",
372 .cold_ids = { NULL },
373 .warm_ids = { &gp8psk_usb_table[GENPIX_8PSK_REV_2], NULL },
375 { .name = "Genpix SkyWalker-1 DVB-S receiver",
376 .cold_ids = { NULL },
377 .warm_ids = { &gp8psk_usb_table[GENPIX_SKYWALKER_1], NULL },
379 { .name = "Genpix SkyWalker-2 DVB-S receiver",
380 .cold_ids = { NULL },
381 .warm_ids = { &gp8psk_usb_table[GENPIX_SKYWALKER_2], NULL },
387 /* usb specific object needed to register this driver with the usb subsystem */
388 static struct usb_driver gp8psk_usb_driver = {
389 .name = "dvb_usb_gp8psk",
390 .probe = gp8psk_usb_probe,
391 .disconnect = dvb_usb_device_exit,
392 .id_table = gp8psk_usb_table,
395 module_usb_driver(gp8psk_usb_driver);
398 MODULE_DESCRIPTION("Driver for Genpix DVB-S");
399 MODULE_VERSION("1.1");
400 MODULE_LICENSE("GPL");