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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * DVB USB Linux driver for Alcor Micro AU6610 DVB-T USB2.0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "au6610.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "zl10353.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "qt1010.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 			  u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	u16 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	u8 *usb_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	 * allocate enough for all known requests,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	 * read returns 5 and write 6 bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	usb_buf = kmalloc(6, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	if (!usb_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	switch (wlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		index = wbuf[0] << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		index = wbuf[0] << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		index += wbuf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		dev_err(&d->udev->dev, "%s: wlen=%d, aborting\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				KBUILD_MODNAME, wlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			      USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			      usb_buf, 6, AU6610_USB_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	dvb_usb_dbg_usb_control_msg(d->udev, operation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			(USB_TYPE_VENDOR|USB_DIR_IN), addr << 1, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			usb_buf, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	switch (operation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	case AU6610_REQ_I2C_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	case AU6610_REQ_USB_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		/* requested value is always 5th byte in buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		rbuf[0] = usb_buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	kfree(usb_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			  u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u8 request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	u8 wo = (rbuf == NULL || rlen == 0); /* write-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (wo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		request = AU6610_REQ_I2C_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	} else { /* rw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		request = AU6610_REQ_I2C_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /* I2C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			   int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (num > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		/* write/read request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 					   msg[i].len, msg[i+1].buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 					   msg[i+1].len) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		} else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 					       msg[i].len, NULL, 0) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	mutex_unlock(&d->i2c_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static u32 au6610_i2c_func(struct i2c_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return I2C_FUNC_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static struct i2c_algorithm au6610_i2c_algo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.master_xfer   = au6610_i2c_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.functionality = au6610_i2c_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* Callbacks for DVB USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static struct zl10353_config au6610_zl10353_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.demod_address = 0x0f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.no_tuner = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.parallel_ts = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	adap->fe[0] = dvb_attach(zl10353_attach, &au6610_zl10353_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			&adap_to_d(adap)->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (adap->fe[0] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return 0;
^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) static struct qt1010_config au6610_qt1010_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	.i2c_address = 0x62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return dvb_attach(qt1010_attach, adap->fe[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			&adap_to_d(adap)->i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			&au6610_qt1010_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int au6610_init(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* TODO: this functionality belongs likely to the streaming control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* bInterfaceNumber 0, bAlternateSetting 5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return usb_set_interface(d->udev, 0, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static struct dvb_usb_device_properties au6610_props = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.driver_name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.adapter_nr = adapter_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.i2c_algo = &au6610_i2c_algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.frontend_attach = au6610_zl10353_frontend_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	.tuner_attach = au6610_qt1010_tuner_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	.init = au6610_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	.num_adapters = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	.adapter = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			.stream = DVB_USB_STREAM_ISOC(0x82, 5, 40, 942, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static const struct usb_device_id au6610_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	{ DVB_USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		&au6610_props, "Sigmatek DVB-110", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) MODULE_DEVICE_TABLE(usb, au6610_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static struct usb_driver au6610_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.id_table = au6610_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	.probe = dvb_usbv2_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	.disconnect = dvb_usbv2_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.suspend = dvb_usbv2_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.resume = dvb_usbv2_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.reset_resume = dvb_usbv2_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.no_dynamic_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.soft_unbind = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) module_usb_driver(au6610_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) MODULE_DESCRIPTION("Driver for Alcor Micro AU6610 DVB-T USB2.0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MODULE_VERSION("0.1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) MODULE_LICENSE("GPL");