0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "gp8psk.h"
0015 #include "gp8psk-fe.h"
0016
0017
0018 static char bcm4500_firmware[] = "dvb-usb-gp8psk-02.fw";
0019 int dvb_usb_gp8psk_debug;
0020 module_param_named(debug,dvb_usb_gp8psk_debug, int, 0644);
0021 MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
0022
0023 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
0024
0025 struct gp8psk_state {
0026 unsigned char data[80];
0027 };
0028
0029 static int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value,
0030 u16 index, u8 *b, int blen)
0031 {
0032 struct gp8psk_state *st = d->priv;
0033 int ret = 0,try = 0;
0034
0035 if (blen > sizeof(st->data))
0036 return -EIO;
0037
0038 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
0039 return ret;
0040
0041 while (ret >= 0 && ret != blen && try < 3) {
0042 ret = usb_control_msg(d->udev,
0043 usb_rcvctrlpipe(d->udev,0),
0044 req,
0045 USB_TYPE_VENDOR | USB_DIR_IN,
0046 value, index, st->data, blen,
0047 2000);
0048 deb_info("reading number %d (ret: %d)\n",try,ret);
0049 try++;
0050 }
0051
0052 if (ret < 0 || ret != blen) {
0053 warn("usb in %d operation failed.", req);
0054 ret = -EIO;
0055 } else {
0056 ret = 0;
0057 memcpy(b, st->data, blen);
0058 }
0059
0060 deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
0061 debug_dump(b,blen,deb_xfer);
0062
0063 mutex_unlock(&d->usb_mutex);
0064
0065 return ret;
0066 }
0067
0068 static int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
0069 u16 index, u8 *b, int blen)
0070 {
0071 struct gp8psk_state *st = d->priv;
0072 int ret;
0073
0074 deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
0075 debug_dump(b,blen,deb_xfer);
0076
0077 if (blen > sizeof(st->data))
0078 return -EIO;
0079
0080 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
0081 return ret;
0082
0083 memcpy(st->data, b, blen);
0084 if (usb_control_msg(d->udev,
0085 usb_sndctrlpipe(d->udev,0),
0086 req,
0087 USB_TYPE_VENDOR | USB_DIR_OUT,
0088 value, index, st->data, blen,
0089 2000) != blen) {
0090 warn("usb out operation failed.");
0091 ret = -EIO;
0092 } else
0093 ret = 0;
0094 mutex_unlock(&d->usb_mutex);
0095
0096 return ret;
0097 }
0098
0099
0100 static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
0101 {
0102 return gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6);
0103 }
0104
0105 static int gp8psk_get_fpga_version(struct dvb_usb_device *d, u8 *fpga_vers)
0106 {
0107 return gp8psk_usb_in_op(d, GET_FPGA_VERS, 0, 0, fpga_vers, 1);
0108 }
0109
0110 static void gp8psk_info(struct dvb_usb_device *d)
0111 {
0112 u8 fpga_vers, fw_vers[6];
0113
0114 if (!gp8psk_get_fw_version(d, fw_vers))
0115 info("FW Version = %i.%02i.%i (0x%x) Build %4i/%02i/%02i",
0116 fw_vers[2], fw_vers[1], fw_vers[0], GP8PSK_FW_VERS(fw_vers),
0117 2000 + fw_vers[5], fw_vers[4], fw_vers[3]);
0118 else
0119 info("failed to get FW version");
0120
0121 if (!gp8psk_get_fpga_version(d, &fpga_vers))
0122 info("FPGA Version = %i", fpga_vers);
0123 else
0124 info("failed to get FPGA version");
0125 }
0126
0127 static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
0128 {
0129 int ret;
0130 const struct firmware *fw = NULL;
0131 const u8 *ptr;
0132 u8 *buf;
0133 if ((ret = request_firmware(&fw, bcm4500_firmware,
0134 &d->udev->dev)) != 0) {
0135 err("did not find the bcm4500 firmware file '%s' (status %d). You can use <kernel_dir>/scripts/get_dvb_firmware to get the firmware",
0136 bcm4500_firmware,ret);
0137 return ret;
0138 }
0139
0140 ret = -EINVAL;
0141
0142 if (gp8psk_usb_out_op(d, LOAD_BCM4500,1,0,NULL, 0))
0143 goto out_rel_fw;
0144
0145 info("downloading bcm4500 firmware from file '%s'",bcm4500_firmware);
0146
0147 ptr = fw->data;
0148 buf = kmalloc(64, GFP_KERNEL);
0149 if (!buf) {
0150 ret = -ENOMEM;
0151 goto out_rel_fw;
0152 }
0153
0154 while (ptr[0] != 0xff) {
0155 u16 buflen = ptr[0] + 4;
0156 if (ptr + buflen >= fw->data + fw->size) {
0157 err("failed to load bcm4500 firmware.");
0158 goto out_free;
0159 }
0160 if (buflen > 64) {
0161 err("firmware chunk size bigger than 64 bytes.");
0162 goto out_free;
0163 }
0164
0165 memcpy(buf, ptr, buflen);
0166 if (dvb_usb_generic_write(d, buf, buflen)) {
0167 err("failed to load bcm4500 firmware.");
0168 goto out_free;
0169 }
0170 ptr += buflen;
0171 }
0172
0173 ret = 0;
0174
0175 out_free:
0176 kfree(buf);
0177 out_rel_fw:
0178 release_firmware(fw);
0179
0180 return ret;
0181 }
0182
0183 static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
0184 {
0185 u8 status = 0, buf;
0186 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
0187
0188 if (onoff) {
0189 gp8psk_usb_in_op(d, GET_8PSK_CONFIG,0,0,&status,1);
0190 if (! (status & bm8pskStarted)) {
0191 if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
0192 gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0);
0193 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
0194 return -EINVAL;
0195 gp8psk_info(d);
0196 }
0197
0198 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
0199 if (! (status & bm8pskFW_Loaded))
0200 if(gp8psk_load_bcm4500fw(d))
0201 return -EINVAL;
0202
0203 if (! (status & bmIntersilOn))
0204 if (gp8psk_usb_in_op(d, START_INTERSIL, 1, 0,
0205 &buf, 1))
0206 return -EINVAL;
0207
0208
0209 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
0210 if (gp8psk_usb_out_op(d, SET_DVB_MODE, 1, 0, NULL, 0))
0211 return -EINVAL;
0212
0213 if (gp8psk_usb_out_op(d, ARM_TRANSFER, 0, 0, NULL, 0))
0214 return -EINVAL;
0215 } else {
0216
0217 if (gp8psk_usb_in_op(d, START_INTERSIL, 0, 0, &buf, 1))
0218 return -EINVAL;
0219
0220 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
0221 return -EINVAL;
0222 if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
0223 gp8psk_usb_out_op(d, CW3K_INIT, 0, 0, NULL, 0);
0224 }
0225 return 0;
0226 }
0227
0228 static int gp8psk_bcm4500_reload(struct dvb_usb_device *d)
0229 {
0230 u8 buf;
0231 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
0232
0233 deb_xfer("reloading firmware\n");
0234
0235
0236 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
0237 return -EINVAL;
0238
0239 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
0240 return -EINVAL;
0241
0242 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
0243 if (gp8psk_load_bcm4500fw(d))
0244 return -EINVAL;
0245 return 0;
0246 }
0247
0248 static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
0249 {
0250 return gp8psk_usb_out_op(adap->dev, ARM_TRANSFER, onoff, 0 , NULL, 0);
0251 }
0252
0253
0254
0255 static int gp8psk_fe_in(void *priv, u8 req, u16 value,
0256 u16 index, u8 *b, int blen)
0257 {
0258 struct dvb_usb_device *d = priv;
0259
0260 return gp8psk_usb_in_op(d, req, value, index, b, blen);
0261 }
0262
0263 static int gp8psk_fe_out(void *priv, u8 req, u16 value,
0264 u16 index, u8 *b, int blen)
0265 {
0266 struct dvb_usb_device *d = priv;
0267
0268 return gp8psk_usb_out_op(d, req, value, index, b, blen);
0269 }
0270
0271 static int gp8psk_fe_reload(void *priv)
0272 {
0273 struct dvb_usb_device *d = priv;
0274
0275 return gp8psk_bcm4500_reload(d);
0276 }
0277
0278 static const struct gp8psk_fe_ops gp8psk_fe_ops = {
0279 .in = gp8psk_fe_in,
0280 .out = gp8psk_fe_out,
0281 .reload = gp8psk_fe_reload,
0282 };
0283
0284 static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap)
0285 {
0286 struct dvb_usb_device *d = adap->dev;
0287 int id = le16_to_cpu(d->udev->descriptor.idProduct);
0288 int is_rev1;
0289
0290 is_rev1 = (id == USB_PID_GENPIX_8PSK_REV_1_WARM) ? true : false;
0291
0292 adap->fe_adap[0].fe = dvb_attach(gp8psk_fe_attach,
0293 &gp8psk_fe_ops, d, is_rev1);
0294 return 0;
0295 }
0296
0297 static struct dvb_usb_device_properties gp8psk_properties;
0298
0299 static int gp8psk_usb_probe(struct usb_interface *intf,
0300 const struct usb_device_id *id)
0301 {
0302 int ret;
0303 struct usb_device *udev = interface_to_usbdev(intf);
0304 ret = dvb_usb_device_init(intf, &gp8psk_properties,
0305 THIS_MODULE, NULL, adapter_nr);
0306 if (ret == 0) {
0307 info("found Genpix USB device pID = %x (hex)",
0308 le16_to_cpu(udev->descriptor.idProduct));
0309 }
0310 return ret;
0311 }
0312
0313 enum {
0314 GENPIX_8PSK_REV_1_COLD,
0315 GENPIX_8PSK_REV_1_WARM,
0316 GENPIX_8PSK_REV_2,
0317 GENPIX_SKYWALKER_1,
0318 GENPIX_SKYWALKER_2,
0319 GENPIX_SKYWALKER_CW3K,
0320 };
0321
0322 static struct usb_device_id gp8psk_usb_table[] = {
0323 DVB_USB_DEV(GENPIX, GENPIX_8PSK_REV_1_COLD),
0324 DVB_USB_DEV(GENPIX, GENPIX_8PSK_REV_1_WARM),
0325 DVB_USB_DEV(GENPIX, GENPIX_8PSK_REV_2),
0326 DVB_USB_DEV(GENPIX, GENPIX_SKYWALKER_1),
0327 DVB_USB_DEV(GENPIX, GENPIX_SKYWALKER_2),
0328 DVB_USB_DEV(GENPIX, GENPIX_SKYWALKER_CW3K),
0329 { }
0330 };
0331
0332 MODULE_DEVICE_TABLE(usb, gp8psk_usb_table);
0333
0334 static struct dvb_usb_device_properties gp8psk_properties = {
0335 .usb_ctrl = CYPRESS_FX2,
0336 .firmware = "dvb-usb-gp8psk-01.fw",
0337
0338 .size_of_priv = sizeof(struct gp8psk_state),
0339
0340 .num_adapters = 1,
0341 .adapter = {
0342 {
0343 .num_frontends = 1,
0344 .fe = {{
0345 .streaming_ctrl = gp8psk_streaming_ctrl,
0346 .frontend_attach = gp8psk_frontend_attach,
0347
0348 .stream = {
0349 .type = USB_BULK,
0350 .count = 7,
0351 .endpoint = 0x82,
0352 .u = {
0353 .bulk = {
0354 .buffersize = 8192,
0355 }
0356 }
0357 },
0358 }},
0359 }
0360 },
0361 .power_ctrl = gp8psk_power_ctrl,
0362
0363 .generic_bulk_ctrl_endpoint = 0x01,
0364
0365 .num_device_descs = 4,
0366 .devices = {
0367 { .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver",
0368 .cold_ids = { &gp8psk_usb_table[GENPIX_8PSK_REV_1_COLD], NULL },
0369 .warm_ids = { &gp8psk_usb_table[GENPIX_8PSK_REV_1_WARM], NULL },
0370 },
0371 { .name = "Genpix 8PSK-to-USB2 Rev.2 DVB-S receiver",
0372 .cold_ids = { NULL },
0373 .warm_ids = { &gp8psk_usb_table[GENPIX_8PSK_REV_2], NULL },
0374 },
0375 { .name = "Genpix SkyWalker-1 DVB-S receiver",
0376 .cold_ids = { NULL },
0377 .warm_ids = { &gp8psk_usb_table[GENPIX_SKYWALKER_1], NULL },
0378 },
0379 { .name = "Genpix SkyWalker-2 DVB-S receiver",
0380 .cold_ids = { NULL },
0381 .warm_ids = { &gp8psk_usb_table[GENPIX_SKYWALKER_2], NULL },
0382 },
0383 { NULL },
0384 }
0385 };
0386
0387
0388 static struct usb_driver gp8psk_usb_driver = {
0389 .name = "dvb_usb_gp8psk",
0390 .probe = gp8psk_usb_probe,
0391 .disconnect = dvb_usb_device_exit,
0392 .id_table = gp8psk_usb_table,
0393 };
0394
0395 module_usb_driver(gp8psk_usb_driver);
0396
0397 MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
0398 MODULE_DESCRIPTION("Driver for Genpix DVB-S");
0399 MODULE_VERSION("1.1");
0400 MODULE_LICENSE("GPL");