Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* DVB USB compliant Linux driver for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Thanks to GENPIX for the sample code used to implement this module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This module is based off the vp7045 and vp702x modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "gp8psk.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "gp8psk-fe.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /* debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static char bcm4500_firmware[] = "dvb-usb-gp8psk-02.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) int dvb_usb_gp8psk_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) module_param_named(debug,dvb_usb_gp8psk_debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct gp8psk_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	unsigned char data[80];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			    u16 index, u8 *b, int blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct gp8psk_state *st = d->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int ret = 0,try = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (blen > sizeof(st->data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	while (ret >= 0 && ret != blen && try < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		ret = usb_control_msg(d->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			usb_rcvctrlpipe(d->udev,0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			USB_TYPE_VENDOR | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			value, index, st->data, blen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		deb_info("reading number %d (ret: %d)\n",try,ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		try++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (ret < 0 || ret != blen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		warn("usb in %d operation failed.", req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		memcpy(b, st->data, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	debug_dump(b,blen,deb_xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	mutex_unlock(&d->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			     u16 index, u8 *b, int blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct gp8psk_state *st = d->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	debug_dump(b,blen,deb_xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (blen > sizeof(st->data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	memcpy(st->data, b, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (usb_control_msg(d->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			usb_sndctrlpipe(d->udev,0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			USB_TYPE_VENDOR | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			value, index, st->data, blen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			2000) != blen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		warn("usb out operation failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	mutex_unlock(&d->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int gp8psk_get_fpga_version(struct dvb_usb_device *d, u8 *fpga_vers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return gp8psk_usb_in_op(d, GET_FPGA_VERS, 0, 0, fpga_vers, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static void gp8psk_info(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	u8 fpga_vers, fw_vers[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (!gp8psk_get_fw_version(d, fw_vers))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		info("FW Version = %i.%02i.%i (0x%x)  Build %4i/%02i/%02i",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		fw_vers[2], fw_vers[1], fw_vers[0], GP8PSK_FW_VERS(fw_vers),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		2000 + fw_vers[5], fw_vers[4], fw_vers[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		info("failed to get FW version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (!gp8psk_get_fpga_version(d, &fpga_vers))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		info("FPGA Version = %i", fpga_vers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		info("failed to get FPGA version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	const struct firmware *fw = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	const u8 *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if ((ret = request_firmware(&fw, bcm4500_firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 					&d->udev->dev)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 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",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			bcm4500_firmware,ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (gp8psk_usb_out_op(d, LOAD_BCM4500,1,0,NULL, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		goto out_rel_fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	info("downloading bcm4500 firmware from file '%s'",bcm4500_firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ptr = fw->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	buf = kmalloc(64, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		goto out_rel_fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	while (ptr[0] != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		u16 buflen = ptr[0] + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (ptr + buflen >= fw->data + fw->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			err("failed to load bcm4500 firmware.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		if (buflen > 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			err("firmware chunk size bigger than 64 bytes.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		memcpy(buf, ptr, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (dvb_usb_generic_write(d, buf, buflen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			err("failed to load bcm4500 firmware.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		ptr += buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) out_rel_fw:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	u8 status = 0, buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (onoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		gp8psk_usb_in_op(d, GET_8PSK_CONFIG,0,0,&status,1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (! (status & bm8pskStarted)) {  /* started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			gp8psk_info(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			if (! (status & bm8pskFW_Loaded)) /* BCM4500 firmware loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				if(gp8psk_load_bcm4500fw(d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 					return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (! (status & bmIntersilOn)) /* LNB Power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			if (gp8psk_usb_in_op(d, START_INTERSIL, 1, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 					&buf, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		/* Set DVB mode to 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			if (gp8psk_usb_out_op(d, SET_DVB_MODE, 1, 0, NULL, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		/* Abort possible TS (if previous tune crashed) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (gp8psk_usb_out_op(d, ARM_TRANSFER, 0, 0, NULL, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		/* Turn off LNB power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (gp8psk_usb_in_op(d, START_INTERSIL, 0, 0, &buf, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		/* Turn off 8psk power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			gp8psk_usb_out_op(d, CW3K_INIT, 0, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int gp8psk_bcm4500_reload(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	u8 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	deb_xfer("reloading firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	/* Turn off 8psk power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* Turn On 8psk power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/* load BCM4500 firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		if (gp8psk_load_bcm4500fw(d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return gp8psk_usb_out_op(adap->dev, ARM_TRANSFER, onoff, 0 , NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* Callbacks for gp8psk-fe.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int gp8psk_fe_in(void *priv, u8 req, u16 value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			    u16 index, u8 *b, int blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct dvb_usb_device *d = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return gp8psk_usb_in_op(d, req, value, index, b, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int gp8psk_fe_out(void *priv, u8 req, u16 value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			    u16 index, u8 *b, int blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct dvb_usb_device *d = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return gp8psk_usb_out_op(d, req, value, index, b, blen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int gp8psk_fe_reload(void *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct dvb_usb_device *d = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return gp8psk_bcm4500_reload(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static const struct gp8psk_fe_ops gp8psk_fe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	.in = gp8psk_fe_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	.out = gp8psk_fe_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	.reload = gp8psk_fe_reload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct dvb_usb_device *d = adap->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int id = le16_to_cpu(d->udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	int is_rev1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	is_rev1 = (id == USB_PID_GENPIX_8PSK_REV_1_WARM) ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	adap->fe_adap[0].fe = dvb_attach(gp8psk_fe_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 					 &gp8psk_fe_ops, d, is_rev1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static struct dvb_usb_device_properties gp8psk_properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int gp8psk_usb_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	ret = dvb_usb_device_init(intf, &gp8psk_properties,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				  THIS_MODULE, NULL, adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		info("found Genpix USB device pID = %x (hex)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			le16_to_cpu(udev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static struct usb_device_id gp8psk_usb_table [] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	    { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_COLD) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	    { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_WARM) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	    { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	    { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_1) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	    { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*	    { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_CW3K) }, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	    { 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) MODULE_DEVICE_TABLE(usb, gp8psk_usb_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static struct dvb_usb_device_properties gp8psk_properties = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.usb_ctrl = CYPRESS_FX2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.firmware = "dvb-usb-gp8psk-01.fw",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.size_of_priv = sizeof(struct gp8psk_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.num_adapters = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.adapter = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		.num_frontends = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		.fe = {{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			.streaming_ctrl   = gp8psk_streaming_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			.frontend_attach  = gp8psk_frontend_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			/* parameter for the MPEG2-data transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			.stream = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				.type = USB_BULK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				.count = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				.endpoint = 0x82,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				.u = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 					.bulk = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 						.buffersize = 8192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		}},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	.power_ctrl       = gp8psk_power_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	.generic_bulk_ctrl_endpoint = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	.num_device_descs = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	.devices = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		{ .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		  .cold_ids = { &gp8psk_usb_table[0], NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		  .warm_ids = { &gp8psk_usb_table[1], NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		{ .name = "Genpix 8PSK-to-USB2 Rev.2 DVB-S receiver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		  .cold_ids = { NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		  .warm_ids = { &gp8psk_usb_table[2], NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		{ .name = "Genpix SkyWalker-1 DVB-S receiver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		  .cold_ids = { NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		  .warm_ids = { &gp8psk_usb_table[3], NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		{ .name = "Genpix SkyWalker-2 DVB-S receiver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		  .cold_ids = { NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		  .warm_ids = { &gp8psk_usb_table[4], NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		{ NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) /* usb specific object needed to register this driver with the usb subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static struct usb_driver gp8psk_usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	.name		= "dvb_usb_gp8psk",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	.probe		= gp8psk_usb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	.disconnect = dvb_usb_device_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	.id_table	= gp8psk_usb_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) module_usb_driver(gp8psk_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) MODULE_DESCRIPTION("Driver for Genpix DVB-S");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) MODULE_VERSION("1.1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) MODULE_LICENSE("GPL");