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 Afatech AF9015 DVB-T USB2.0 receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2007 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)  * Thanks to Afatech who kindly provided information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include "af9015.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) static int dvb_usb_af9015_remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) MODULE_PARM_DESC(remote, "select remote");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #define REQ_HDR_LEN 8 /* send header size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #define ACK_HDR_LEN 2 /* rece header size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 	int ret, wlen, rlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 	u8 write = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 	mutex_lock(&d->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 	state->buf[0] = req->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 	state->buf[1] = state->seq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 	state->buf[2] = req->i2c_addr << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	state->buf[3] = req->addr >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	state->buf[4] = req->addr & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	state->buf[5] = req->mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 	state->buf[6] = req->addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 	state->buf[7] = req->data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 	switch (req->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 	case GET_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	case READ_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	case RECONNECT_USB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 		write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	case READ_I2C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 		write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 		state->buf[2] |= 0x01; /* set I2C direction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	case WRITE_I2C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 		state->buf[0] = READ_WRITE_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	case WRITE_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		if (((req->addr & 0xff00) == 0xff00) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 		    ((req->addr & 0xff00) == 0xae00))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 			state->buf[0] = WRITE_VIRTUAL_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	case WRITE_VIRTUAL_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	case COPY_FIRMWARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	case DOWNLOAD_FIRMWARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	case BOOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 		dev_err(&intf->dev, "unknown cmd %d\n", req->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	/* Buffer overflow check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	    (!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 		dev_err(&intf->dev, "too much data, cmd %u, len %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 			req->cmd, req->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	 * Write receives seq + status = 2 bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	 * Read receives seq + status + data = 2 + N bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	wlen = REQ_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	rlen = ACK_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	if (write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 		wlen += req->data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		memcpy(&state->buf[REQ_HDR_LEN], req->data, req->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		rlen += req->data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	/* no ack for these packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		rlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	ret = dvb_usbv2_generic_rw_locked(d, state->buf, wlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 					  state->buf, rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	/* check status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	if (rlen && state->buf[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 		dev_err(&intf->dev, "cmd failed %u\n", state->buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	/* read request, copy returned data to return buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	if (!write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 		memcpy(req->data, &state->buf[ACK_HDR_LEN], req->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	mutex_unlock(&d->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	return ret;
^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) static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 				u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	if (addr == state->af9013_i2c_addr[0] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	    addr == state->af9013_i2c_addr[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		req.addr_len = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	return af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 			       u8 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	if (addr == state->af9013_i2c_addr[0] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	    addr == state->af9013_i2c_addr[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		req.addr_len = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	return af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 			   int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	u16 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	u8 mbox, addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	struct req_t req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	 * I2C multiplexing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	 * There could be two tuners, both using same I2C address. Demodulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	 * I2C-gate is only possibility to select correct tuner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	 * ...........................................
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	 * . AF9015 integrates AF9013 demodulator    .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	 * . ____________               ____________ .             ____________
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	 * .|   USB IF   |             |   demod    |.            |   tuner    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	 * .|------------|             |------------|.            |------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	 * .|   AF9015   |             |   AF9013   |.            |   MXL5003  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	 * .|            |--+--I2C-----|-----/ -----|.----I2C-----|            |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	 * .|            |  |          | addr 0x1c  |.            |  addr 0x63 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	 * .|____________|  |          |____________|.            |____________|
^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) 	 *                  |          |   demod    |             |   tuner    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	 *                  |          |------------|             |------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	 *                  |          |   AF9013   |             |   MXL5003  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	 *                  +--I2C-----|-----/ -----|-----I2C-----|            |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	 *                             | addr 0x1d  |             |  addr 0x63 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	 *                             |____________|             |____________|
^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) 	if (msg[0].len == 0 || msg[0].flags & I2C_M_RD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		addr = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		mbox = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		addr_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	} else if (msg[0].len == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		addr = msg[0].buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		mbox = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		addr_len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	} else if (msg[0].len == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		addr = msg[0].buf[0] << 8 | msg[0].buf[1] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		mbox = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		addr_len = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		addr = msg[0].buf[0] << 8 | msg[0].buf[1] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		mbox = msg[0].buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		addr_len = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		/* i2c write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		if (msg[0].len > 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 			ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		if (msg[0].addr == state->af9013_i2c_addr[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 			req.cmd = WRITE_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 			req.cmd = WRITE_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		req.i2c_addr = msg[0].addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		req.addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		req.mbox = mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		req.addr_len = addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		req.data_len = msg[0].len - addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		req.data = &msg[0].buf[addr_len];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	} else if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		   (msg[1].flags & I2C_M_RD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		/* i2c write + read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		if (msg[0].len > 3 || msg[1].len > 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 			ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		if (msg[0].addr == state->af9013_i2c_addr[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 			req.cmd = READ_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 			req.cmd = READ_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		req.i2c_addr = msg[0].addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		req.addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		req.mbox = mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		req.addr_len = addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		req.data_len = msg[1].len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		req.data = &msg[1].buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	} else if (num == 1 && (msg[0].flags & I2C_M_RD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		/* i2c read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		if (msg[0].len > 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 			ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		if (msg[0].addr == state->af9013_i2c_addr[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		req.cmd = READ_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		req.i2c_addr = msg[0].addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		req.addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		req.mbox = mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		req.addr_len = addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		req.data_len = msg[0].len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		req.data = &msg[0].buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		dev_dbg(&intf->dev, "unknown msg, num %u\n", num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) static u32 af9015_i2c_func(struct i2c_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	return I2C_FUNC_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) static struct i2c_algorithm af9015_i2c_algo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	.master_xfer = af9015_i2c_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	.functionality = af9015_i2c_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) static int af9015_identify_state(struct dvb_usb_device *d, const char **name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	u8 reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	dev_dbg(&intf->dev, "reply %02x\n", reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	if (reply == 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		ret = WARM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		ret = COLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) static int af9015_download_firmware(struct dvb_usb_device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 				    const struct firmware *firmware)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	int ret, i, rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	u16 checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	dev_dbg(&intf->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	/* Calc checksum, we need it when copy firmware to slave demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	for (i = 0, checksum = 0; i < firmware->size; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		checksum += firmware->data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	state->firmware_size = firmware->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	state->firmware_checksum = checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	#define LEN_MAX (BUF_LEN - REQ_HDR_LEN) /* Max payload size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	for (rem = firmware->size; rem > 0; rem -= LEN_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		req.data_len = min(LEN_MAX, rem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		req.data = (u8 *)&firmware->data[firmware->size - rem];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		req.addr = 0x5100 + firmware->size - rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 			dev_err(&intf->dev, "firmware download failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 				ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	req.cmd = BOOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	req.data_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		dev_err(&intf->dev, "firmware boot failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) #define AF9015_EEPROM_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) #define GOLDEN_RATIO_PRIME_32 0x9e370001UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) /* hash (and dump) eeprom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) static int af9015_eeprom_hash(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	u8 buf[AF9015_EEPROM_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	/* read eeprom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	for (i = 0; i < AF9015_EEPROM_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		req.addr = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		req.data = &buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	/* calculate checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	for (i = 0; i < AF9015_EEPROM_SIZE / sizeof(u32); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		state->eeprom_sum *= GOLDEN_RATIO_PRIME_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		state->eeprom_sum += le32_to_cpu(((__le32 *)buf)[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	for (i = 0; i < AF9015_EEPROM_SIZE; i += 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		dev_dbg(&intf->dev, "%*ph\n", 16, buf + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	dev_dbg(&intf->dev, "eeprom sum %.8x\n", state->eeprom_sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) static int af9015_read_config(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	u8 val, i, offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	dev_dbg(&intf->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	/* IR remote controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	req.addr = AF9015_EEPROM_IR_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	/* first message will timeout often due to possible hw bug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	ret = af9015_eeprom_hash(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	state->ir_mode = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	dev_dbg(&intf->dev, "ir mode %02x\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	/* TS mode - one or two receivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	req.addr = AF9015_EEPROM_TS_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	state->dual_mode = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	dev_dbg(&intf->dev, "ts mode %02x\n", state->dual_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	state->af9013_i2c_addr[0] = AF9015_I2C_DEMOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	if (state->dual_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		/* read 2nd demodulator I2C address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		req.addr = AF9015_EEPROM_DEMOD2_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		state->af9013_i2c_addr[1] = val >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	for (i = 0; i < state->dual_mode + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		if (i == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			offset = AF9015_EEPROM_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		/* xtal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 			state->af9013_pdata[i].clk = 28800000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			state->af9013_pdata[i].clk = 20480000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 			state->af9013_pdata[i].clk = 28000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 			state->af9013_pdata[i].clk = 25000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		dev_dbg(&intf->dev, "[%d] xtal %02x, clk %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			i, val, state->af9013_pdata[i].clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		/* IF frequency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		req.addr = AF9015_EEPROM_IF1H + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		state->af9013_pdata[i].if_frequency = val << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		req.addr = AF9015_EEPROM_IF1L + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		state->af9013_pdata[i].if_frequency += val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		state->af9013_pdata[i].if_frequency *= 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		dev_dbg(&intf->dev, "[%d] if frequency %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			i, state->af9013_pdata[i].if_frequency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		/* MT2060 IF1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		req.addr = AF9015_EEPROM_MT2060_IF1H  + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		state->mt2060_if1[i] = val << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		req.addr = AF9015_EEPROM_MT2060_IF1L + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		state->mt2060_if1[i] += val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		dev_dbg(&intf->dev, "[%d] MT2060 IF1 %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			i, state->mt2060_if1[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		/* tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		req.addr =  AF9015_EEPROM_TUNER_ID1 + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		case AF9013_TUNER_ENV77H11D5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		case AF9013_TUNER_MT2060:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		case AF9013_TUNER_QT1010:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		case AF9013_TUNER_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		case AF9013_TUNER_MT2060_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		case AF9013_TUNER_TDA18271:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		case AF9013_TUNER_QT1010A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		case AF9013_TUNER_TDA18218:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			state->af9013_pdata[i].spec_inv = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		case AF9013_TUNER_MXL5003D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		case AF9013_TUNER_MXL5005D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		case AF9013_TUNER_MXL5005R:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		case AF9013_TUNER_MXL5007T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			state->af9013_pdata[i].spec_inv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		case AF9013_TUNER_MC44S803:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			state->af9013_pdata[i].gpio[1] = AF9013_GPIO_LO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			state->af9013_pdata[i].spec_inv = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 				"tuner id %02x not supported, please report!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 				val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		state->af9013_pdata[i].tuner = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		dev_dbg(&intf->dev, "[%d] tuner id %02x\n", i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		dev_err(&intf->dev, "eeprom read failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	 * AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	 * content :-( Override some wrong values here. Ditto for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	 * AVerTV Red HD+ (A850T) device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_AVERMEDIA &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	    ((le16_to_cpu(d->udev->descriptor.idProduct) == USB_PID_AVERMEDIA_A850) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	    (le16_to_cpu(d->udev->descriptor.idProduct) == USB_PID_AVERMEDIA_A850T))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		dev_dbg(&intf->dev, "AverMedia A850: overriding config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		/* disable dual mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		state->dual_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		/* set correct IF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		state->af9013_pdata[0].if_frequency = 4570000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) static int af9015_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 				    struct usb_data_stream_properties *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	struct dvb_usb_device *d = fe_to_d(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	dev_dbg(&intf->dev, "adap %u\n", fe_to_adap(fe)->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	if (d->udev->speed == USB_SPEED_FULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		stream->u.bulk.buffersize = 5 * 188;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) static int af9015_streaming_ctrl(struct dvb_frontend *fe, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	struct dvb_usb_device *d = fe_to_d(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	unsigned int utmp1, utmp2, reg1, reg2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	u8 buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	const unsigned int adap_id = fe_to_adap(fe)->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	dev_dbg(&intf->dev, "adap id %d, onoff %d\n", adap_id, onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	if (!state->usb_ts_if_configured[adap_id]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		dev_dbg(&intf->dev, "set usb and ts interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		/* USB IF stream settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		utmp1 = (d->udev->speed == USB_SPEED_FULL ? 5 : 87) * 188 / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		utmp2 = (d->udev->speed == USB_SPEED_FULL ? 64 : 512) / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		buf[0] = (utmp1 >> 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		buf[1] = (utmp1 >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		if (adap_id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 			/* 1st USB IF (EP4) stream settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 			reg1 = 0xdd88;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 			reg2 = 0xdd0c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 			/* 2nd USB IF (EP5) stream settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			reg1 = 0xdd8a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			reg2 = 0xdd0d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		ret = regmap_bulk_write(state->regmap, reg1, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		ret = regmap_write(state->regmap, reg2, utmp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		/* TS IF settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		if (state->dual_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 			utmp1 = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 			utmp2 = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 			utmp1 = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 			utmp2 = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		ret = regmap_update_bits(state->regmap, 0xd50b, 0x01, utmp1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		ret = regmap_update_bits(state->regmap, 0xd520, 0x10, utmp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		state->usb_ts_if_configured[adap_id] = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	if (adap_id == 0 && onoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		/* Adapter 0 stream on. EP4: clear NAK, enable, clear reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		ret = regmap_update_bits(state->regmap, 0xdd13, 0x20, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		ret = regmap_update_bits(state->regmap, 0xdd11, 0x20, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		ret = regmap_update_bits(state->regmap, 0xd507, 0x04, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	} else if (adap_id == 1 && onoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		/* Adapter 1 stream on. EP5: clear NAK, enable, clear reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		ret = regmap_update_bits(state->regmap, 0xdd13, 0x40, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		ret = regmap_update_bits(state->regmap, 0xdd11, 0x40, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		ret = regmap_update_bits(state->regmap, 0xd50b, 0x02, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	} else if (adap_id == 0 && !onoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		/* Adapter 0 stream off. EP4: set reset, disable, set NAK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		ret = regmap_update_bits(state->regmap, 0xd507, 0x04, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		ret = regmap_update_bits(state->regmap, 0xdd11, 0x20, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		ret = regmap_update_bits(state->regmap, 0xdd13, 0x20, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	} else if (adap_id == 1 && !onoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		/* Adapter 1 stream off. EP5: set reset, disable, set NAK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		ret = regmap_update_bits(state->regmap, 0xd50b, 0x02, 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		ret = regmap_update_bits(state->regmap, 0xdd11, 0x40, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		ret = regmap_update_bits(state->regmap, 0xdd13, 0x40, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) static int af9015_get_adapter_count(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	return state->dual_mode + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) /* override demod callbacks for resource locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) static int af9015_af9013_set_frontend(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	struct af9015_state *state = fe_to_priv(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	if (mutex_lock_interruptible(&state->fe_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	ret = state->set_frontend[fe_to_adap(fe)->id](fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) /* override demod callbacks for resource locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) static int af9015_af9013_read_status(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 				     enum fe_status *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	struct af9015_state *state = fe_to_priv(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	if (mutex_lock_interruptible(&state->fe_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	ret = state->read_status[fe_to_adap(fe)->id](fe, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) /* override demod callbacks for resource locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) static int af9015_af9013_init(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	struct af9015_state *state = fe_to_priv(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	if (mutex_lock_interruptible(&state->fe_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	ret = state->init[fe_to_adap(fe)->id](fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) /* override demod callbacks for resource locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) static int af9015_af9013_sleep(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	struct af9015_state *state = fe_to_priv(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	if (mutex_lock_interruptible(&state->fe_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	ret = state->sleep[fe_to_adap(fe)->id](fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) /* override tuner callbacks for resource locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) static int af9015_tuner_init(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	struct af9015_state *state = fe_to_priv(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	if (mutex_lock_interruptible(&state->fe_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	ret = state->tuner_init[fe_to_adap(fe)->id](fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) /* override tuner callbacks for resource locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) static int af9015_tuner_sleep(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	struct af9015_state *state = fe_to_priv(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	if (mutex_lock_interruptible(&state->fe_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	ret = state->tuner_sleep[fe_to_adap(fe)->id](fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) static int af9015_copy_firmware(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	u8 val, firmware_info[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, 4, firmware_info};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	dev_dbg(&intf->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	firmware_info[0] = (state->firmware_size >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	firmware_info[1] = (state->firmware_size >> 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	firmware_info[2] = (state->firmware_checksum >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	firmware_info[3] = (state->firmware_checksum >> 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	/* Check whether firmware is already running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	ret = af9015_read_reg_i2c(d, state->af9013_i2c_addr[1], 0x98be, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	dev_dbg(&intf->dev, "firmware status %02x\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	if (val == 0x0c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	/* Set i2c clock to 625kHz to speed up firmware copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	ret = regmap_write(state->regmap, 0xd416, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	/* Copy firmware from master demod to slave demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		dev_err(&intf->dev, "firmware copy cmd failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	/* Set i2c clock to 125kHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	ret = regmap_write(state->regmap, 0xd416, 0x14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	/* Boot firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	ret = af9015_write_reg_i2c(d, state->af9013_i2c_addr[1], 0xe205, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	/* Poll firmware ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	for (val = 0x00, timeout = jiffies + msecs_to_jiffies(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	     !time_after(jiffies, timeout) && val != 0x0c && val != 0x04;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		/* Check firmware status. 0c=OK, 04=fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		ret = af9015_read_reg_i2c(d, state->af9013_i2c_addr[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 					  0x98be, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		dev_dbg(&intf->dev, "firmware status %02x\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	dev_dbg(&intf->dev, "firmware boot took %u ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		jiffies_to_msecs(jiffies) - (jiffies_to_msecs(timeout) - 1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	if (val == 0x04) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		dev_err(&intf->dev, "firmware did not run\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	} else if (val != 0x0c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		ret = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		dev_err(&intf->dev, "firmware boot timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	struct af9015_state *state = adap_to_priv(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	struct dvb_usb_device *d = adap_to_d(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	dev_dbg(&intf->dev, "adap id %u\n", adap->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	if (adap->id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		state->af9013_pdata[0].ts_mode = AF9013_TS_MODE_USB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		memcpy(state->af9013_pdata[0].api_version, "\x0\x1\x9\x0", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		state->af9013_pdata[0].gpio[0] = AF9013_GPIO_HI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		state->af9013_pdata[0].gpio[3] = AF9013_GPIO_TUNER_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	} else if (adap->id == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		state->af9013_pdata[1].ts_mode = AF9013_TS_MODE_SERIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		state->af9013_pdata[1].ts_output_pin = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		memcpy(state->af9013_pdata[1].api_version, "\x0\x1\x9\x0", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		state->af9013_pdata[1].gpio[0] = AF9013_GPIO_TUNER_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		state->af9013_pdata[1].gpio[1] = AF9013_GPIO_LO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		/* copy firmware to 2nd demodulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		if (state->dual_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 			/* Wait 2nd demodulator ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 			ret = af9015_copy_firmware(adap_to_d(adap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 				dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 					"firmware copy to 2nd frontend failed, will disable it\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 				state->dual_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 			ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	/* Add I2C demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	client = dvb_module_probe("af9013", NULL, &d->i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 				  state->af9013_i2c_addr[adap->id],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 				  &state->af9013_pdata[adap->id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	if (!client) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	adap->fe[0] = state->af9013_pdata[adap->id].get_dvb_frontend(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	state->demod_i2c_client[adap->id] = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	 * AF9015 firmware does not like if it gets interrupted by I2C adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	 * request on some critical phases. During normal operation I2C adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	 * is used only 2nd demodulator and tuner on dual tuner devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	 * Override demodulator callbacks and use mutex for limit access to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	 * those "critical" paths to keep AF9015 happy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	if (adap->fe[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		state->set_frontend[adap->id] = adap->fe[0]->ops.set_frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		adap->fe[0]->ops.set_frontend = af9015_af9013_set_frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		state->read_status[adap->id] = adap->fe[0]->ops.read_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		adap->fe[0]->ops.read_status = af9015_af9013_read_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		state->init[adap->id] = adap->fe[0]->ops.init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		adap->fe[0]->ops.init = af9015_af9013_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		state->sleep[adap->id] = adap->fe[0]->ops.sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		adap->fe[0]->ops.sleep = af9015_af9013_sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) static int af9015_frontend_detach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	struct af9015_state *state = adap_to_priv(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	struct dvb_usb_device *d = adap_to_d(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	dev_dbg(&intf->dev, "adap id %u\n", adap->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	/* Remove I2C demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	client = state->demod_i2c_client[adap->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	dvb_module_release(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) static struct mt2060_config af9015_mt2060_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	.i2c_address = 0x60,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	.clock_out = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) static struct qt1010_config af9015_qt1010_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	.i2c_address = 0x62,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) static struct tda18271_config af9015_tda18271_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	.gate = TDA18271_GATE_DIGITAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	.small_i2c = TDA18271_16_BYTE_CHUNK_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) static struct mxl5005s_config af9015_mxl5003_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	.i2c_address     = 0x63,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	.if_freq         = IF_FREQ_4570000HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	.xtal_freq       = CRYSTAL_FREQ_16000000HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	.agc_mode        = MXL_SINGLE_AGC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	.tracking_filter = MXL_TF_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	.rssi_enable     = MXL_RSSI_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	.cap_select      = MXL_CAP_SEL_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	.div_out         = MXL_DIV_OUT_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	.clock_out       = MXL_CLOCK_OUT_DISABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	.output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	.top		 = MXL5005S_TOP_25P2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	.mod_mode        = MXL_DIGITAL_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	.if_mode         = MXL_ZERO_IF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	.AgcMasterByte   = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) static struct mxl5005s_config af9015_mxl5005_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	.i2c_address     = 0x63,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	.if_freq         = IF_FREQ_4570000HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	.xtal_freq       = CRYSTAL_FREQ_16000000HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	.agc_mode        = MXL_SINGLE_AGC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	.tracking_filter = MXL_TF_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	.rssi_enable     = MXL_RSSI_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	.cap_select      = MXL_CAP_SEL_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	.div_out         = MXL_DIV_OUT_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	.clock_out       = MXL_CLOCK_OUT_DISABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	.output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	.top		 = MXL5005S_TOP_25P2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	.mod_mode        = MXL_DIGITAL_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	.if_mode         = MXL_ZERO_IF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	.AgcMasterByte   = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) static struct mc44s803_config af9015_mc44s803_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	.i2c_address = 0x60,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	.dig_out = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) static struct tda18218_config af9015_tda18218_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	.i2c_address = 0x60,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	.i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) static struct mxl5007t_config af9015_mxl5007t_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	.xtal_freq_hz = MxL_XTAL_24_MHZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	.if_freq_hz = MxL_IF_4_57_MHZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	struct dvb_usb_device *d = adap_to_d(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	struct i2c_adapter *adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	dev_dbg(&intf->dev, "adap id %u\n", adap->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	client = state->demod_i2c_client[adap->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	adapter = state->af9013_pdata[adap->id].get_i2c_adapter(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	switch (state->af9013_pdata[adap->id].tuner) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	case AF9013_TUNER_MT2060:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	case AF9013_TUNER_MT2060_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		ret = dvb_attach(mt2060_attach, adap->fe[0], adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 				 &af9015_mt2060_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 				 state->mt2060_if1[adap->id]) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	case AF9013_TUNER_QT1010:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	case AF9013_TUNER_QT1010A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		ret = dvb_attach(qt1010_attach, adap->fe[0], adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 				 &af9015_qt1010_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	case AF9013_TUNER_TDA18271:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		ret = dvb_attach(tda18271_attach, adap->fe[0], 0x60, adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 				 &af9015_tda18271_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	case AF9013_TUNER_TDA18218:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		ret = dvb_attach(tda18218_attach, adap->fe[0], adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				 &af9015_tda18218_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	case AF9013_TUNER_MXL5003D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		ret = dvb_attach(mxl5005s_attach, adap->fe[0], adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 				 &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	case AF9013_TUNER_MXL5005D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	case AF9013_TUNER_MXL5005R:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		ret = dvb_attach(mxl5005s_attach, adap->fe[0], adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 				 &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	case AF9013_TUNER_ENV77H11D5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		ret = dvb_attach(dvb_pll_attach, adap->fe[0], 0x60, adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 				 DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	case AF9013_TUNER_MC44S803:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		ret = dvb_attach(mc44s803_attach, adap->fe[0], adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 				 &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	case AF9013_TUNER_MXL5007T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		ret = dvb_attach(mxl5007t_attach, adap->fe[0], adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 				 0x60, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	case AF9013_TUNER_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		dev_err(&intf->dev, "unknown tuner, tuner id %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 			state->af9013_pdata[adap->id].tuner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	if (adap->fe[0]->ops.tuner_ops.init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		state->tuner_init[adap->id] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 			adap->fe[0]->ops.tuner_ops.init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		adap->fe[0]->ops.tuner_ops.init = af9015_tuner_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	if (adap->fe[0]->ops.tuner_ops.sleep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		state->tuner_sleep[adap->id] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 			adap->fe[0]->ops.tuner_ops.sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		adap->fe[0]->ops.tuner_ops.sleep = af9015_tuner_sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	struct af9015_state *state = adap_to_priv(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	struct af9013_platform_data *pdata = &state->af9013_pdata[adap->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	mutex_lock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	ret = pdata->pid_filter_ctrl(adap->fe[0], onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 			     u16 pid, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	struct af9015_state *state = adap_to_priv(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	struct af9013_platform_data *pdata = &state->af9013_pdata[adap->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	mutex_lock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	ret = pdata->pid_filter(adap->fe[0], index, pid, onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	mutex_unlock(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static int af9015_init(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	dev_dbg(&intf->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	mutex_init(&state->fe_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	/* init RC canary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	ret = regmap_write(state->regmap, 0x98e9, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) #if IS_ENABLED(CONFIG_RC_CORE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) struct af9015_rc_setup {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	char *rc_codes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static char *af9015_rc_setup_match(unsigned int id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 				   const struct af9015_rc_setup *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	for (; table->rc_codes; table++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		if (table->id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			return table->rc_codes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) static const struct af9015_rc_setup af9015_rc_setup_modparam[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	{ AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	{ AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	{ AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	{ AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	{ AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	{ 0xb8feb708, RC_MAP_MSI_DIGIVOX_II },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	{ 0xa3703d00, RC_MAP_ALINK_DTU_M },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	{ 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	{ 0x5d49e3db, RC_MAP_DIGITTRADE }, /* LC-Power LC-USB-DVBT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) static int af9015_rc_query(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	u8 buf[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	/* read registers needed to detect remote controller code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	ret = regmap_bulk_read(state->regmap, 0x98d9, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	/* If any of these are non-zero, assume invalid data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	if (buf[1] || buf[2] || buf[3]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		dev_dbg(&intf->dev, "invalid data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	/* Check for repeat of previous code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	if ((state->rc_repeat != buf[6] || buf[0]) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	    !memcmp(&buf[12], state->rc_last, 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		dev_dbg(&intf->dev, "key repeated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		rc_repeat(d->rc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		state->rc_repeat = buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	/* Only process key if canary killed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	if (buf[16] != 0xff && buf[0] != 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 		enum rc_proto proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		dev_dbg(&intf->dev, "key pressed %*ph\n", 4, buf + 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		/* Reset the canary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		ret = regmap_write(state->regmap, 0x98e9, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		/* Remember this key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		memcpy(state->rc_last, &buf[12], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		if (buf[14] == (u8)~buf[15]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 			if (buf[12] == (u8)~buf[13]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 				/* NEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 				state->rc_keycode = RC_SCANCODE_NEC(buf[12],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 								    buf[14]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 				proto = RC_PROTO_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 				/* NEC extended*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 				state->rc_keycode = RC_SCANCODE_NECX(buf[12] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 								     buf[13],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 								     buf[14]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 				proto = RC_PROTO_NECX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 			/* 32 bit NEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 			state->rc_keycode = RC_SCANCODE_NEC32(buf[12] << 24 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 							      buf[13] << 16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 							      buf[14] << 8  |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 							      buf[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 			proto = RC_PROTO_NEC32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		rc_keydown(d->rc_dev, proto, state->rc_keycode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		dev_dbg(&intf->dev, "no key press\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		/* Invalidate last keypress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		/* Not really needed, but helps with debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		state->rc_last[2] = state->rc_last[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	state->rc_repeat = buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	state->rc_failed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		dev_warn(&intf->dev, "rc query failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		/* allow random errors as dvb-usb will stop polling on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		if (!state->rc_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		state->rc_failed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) static int af9015_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	u16 vid = le16_to_cpu(d->udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	if (state->ir_mode == AF9015_IR_MODE_DISABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	/* try to load remote based module param */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	if (!rc->map_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		rc->map_name = af9015_rc_setup_match(dvb_usb_af9015_remote,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 						     af9015_rc_setup_modparam);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	/* try to load remote based eeprom hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	if (!rc->map_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		rc->map_name = af9015_rc_setup_match(state->eeprom_sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 						     af9015_rc_setup_hashes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	/* try to load remote based USB iManufacturer string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	if (!rc->map_name && vid == USB_VID_AFATECH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 		 * Check USB manufacturer and product strings and try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		 * to determine correct remote in case of chip vendor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		 * reference IDs are used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		 * DO NOT ADD ANYTHING NEW HERE. Use hashes instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		char manufacturer[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		memset(manufacturer, 0, sizeof(manufacturer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		usb_string(d->udev, d->udev->descriptor.iManufacturer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 			   manufacturer, sizeof(manufacturer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		if (!strcmp("MSI", manufacturer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 			 * iManufacturer 1 MSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 			 * iProduct      2 MSI K-VOX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 			rc->map_name = af9015_rc_setup_match(AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 							     af9015_rc_setup_modparam);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	/* load empty to enable rc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	if (!rc->map_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		rc->map_name = RC_MAP_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	rc->allowed_protos = RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 						RC_PROTO_BIT_NEC32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	rc->query = af9015_rc_query;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	rc->interval = 500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	#define af9015_get_rc_config NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) static int af9015_regmap_write(void *context, const void *data, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	struct dvb_usb_device *d = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	u16 reg = ((u8 *)data)[0] << 8 | ((u8 *)data)[1] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	u8 *val = &((u8 *)data)[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	const unsigned int len = count - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	struct req_t req = {WRITE_MEMORY, 0, reg, 0, 0, len, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) static int af9015_regmap_read(void *context, const void *reg_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 			      size_t reg_size, void *val_buf, size_t val_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	struct dvb_usb_device *d = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	u16 reg = ((u8 *)reg_buf)[0] << 8 | ((u8 *)reg_buf)[1] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	u8 *val = &((u8 *)val_buf)[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	const unsigned int len = val_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	struct req_t req = {READ_MEMORY, 0, reg, 0, 0, len, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	ret = af9015_ctrl_msg(d, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) static int af9015_probe(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	char manufacturer[sizeof("ITE Technologies, Inc.")];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	static const struct regmap_config regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		.reg_bits    =  16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		.val_bits    =  8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	static const struct regmap_bus regmap_bus = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		.read = af9015_regmap_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		.write = af9015_regmap_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	dev_dbg(&intf->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	memset(manufacturer, 0, sizeof(manufacturer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	usb_string(udev, udev->descriptor.iManufacturer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		   manufacturer, sizeof(manufacturer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	 * There is two devices having same ID but different chipset. One uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	 * AF9015 and the other IT9135 chipset. Only difference seen on lsusb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	 * is iManufacturer string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	 * idVendor           0x0ccd TerraTec Electronic GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	 * idProduct          0x0099
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	 * bcdDevice            2.00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	 * iManufacturer           1 Afatech
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	 * iProduct                2 DVB-T 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	 * idVendor           0x0ccd TerraTec Electronic GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	 * idProduct          0x0099
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	 * bcdDevice            2.00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	 * iManufacturer           1 ITE Technologies, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	 * iProduct                2 DVB-T TV Stick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VID_TERRATEC) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	    (le16_to_cpu(udev->descriptor.idProduct) == 0x0099)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		if (!strcmp("ITE Technologies, Inc.", manufacturer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 			ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 			dev_dbg(&intf->dev, "rejecting device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	state->regmap = regmap_init(&intf->dev, &regmap_bus, d, &regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	if (IS_ERR(state->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		ret = PTR_ERR(state->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	dev_dbg(&intf->dev, "failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) static void af9015_disconnect(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	struct af9015_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	struct usb_interface *intf = d->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	dev_dbg(&intf->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	regmap_exit(state->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)  * Interface 0 is used by DVB-T receiver and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)  * interface 1 is for remote controller (HID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) static const struct dvb_usb_device_properties af9015_props = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	.driver_name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	.adapter_nr = adapter_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	.size_of_priv = sizeof(struct af9015_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	.generic_bulk_ctrl_endpoint = 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	.generic_bulk_ctrl_endpoint_response = 0x81,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	.probe = af9015_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	.disconnect = af9015_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	.identify_state = af9015_identify_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	.firmware = AF9015_FIRMWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	.download_firmware = af9015_download_firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	.i2c_algo = &af9015_i2c_algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	.read_config = af9015_read_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	.frontend_attach = af9015_af9013_frontend_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	.frontend_detach = af9015_frontend_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	.tuner_attach = af9015_tuner_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	.init = af9015_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	.get_rc_config = af9015_get_rc_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	.get_stream_config = af9015_get_stream_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	.streaming_ctrl = af9015_streaming_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	.get_adapter_count = af9015_get_adapter_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	.adapter = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 			.caps = DVB_USB_ADAP_HAS_PID_FILTER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 				DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 			.pid_filter_count = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 			.pid_filter = af9015_pid_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			.pid_filter_ctrl = af9015_pid_filter_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 			.stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 			.caps = DVB_USB_ADAP_HAS_PID_FILTER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 				DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			.pid_filter_count = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			.pid_filter = af9015_pid_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 			.pid_filter_ctrl = af9015_pid_filter_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 			.stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) static const struct usb_device_id af9015_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	{ DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 		&af9015_props, "Afatech AF9015 reference design", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	{ DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 		&af9015_props, "Afatech AF9015 reference design", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	{ DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		&af9015_props, "Leadtek WinFast DTV Dongle Gold", RC_MAP_LEADTEK_Y04G0051) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	{ DVB_USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 		&af9015_props, "Pinnacle PCTV 71e", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		&af9015_props, "KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	{ DVB_USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TINYTWIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		&af9015_props, "DigitalNow TinyTwin", RC_MAP_AZUREWAVE_AD_TU700) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	{ DVB_USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_AZUREWAVE_AD_TU700,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		&af9015_props, "TwinHan AzureWave AD-TU700(704J)", RC_MAP_AZUREWAVE_AD_TU700) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	{ DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		&af9015_props, "TerraTec Cinergy T USB XE", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		&af9015_props, "KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		&af9015_props, "AVerMedia AVerTV DVB-T Volar X", RC_MAP_AVERMEDIA_M135A) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	{ DVB_USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		&af9015_props, "Xtensions XD-380", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	{ DVB_USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		&af9015_props, "MSI DIGIVOX Duo", RC_MAP_MSI_DIGIVOX_III) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		&af9015_props, "Fujitsu-Siemens Slim Mobile USB DVB-T", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	{ DVB_USB_DEVICE(USB_VID_TELESTAR,  USB_PID_TELESTAR_STARSTICK_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		&af9015_props, "Telestar Starstick 2", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 		&af9015_props, "AVerMedia A309", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	{ DVB_USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		&af9015_props, "MSI Digi VOX mini III", RC_MAP_MSI_DIGIVOX_III) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		&af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 		&af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 		&af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	{ DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_TREKSTOR_DVBT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		&af9015_props, "TrekStor DVB-T USB Stick", RC_MAP_TREKSTOR) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		&af9015_props, "AverMedia AVerTV Volar Black HD (A850)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A805,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		&af9015_props, "AverMedia AVerTV Volar GPS 805 (A805)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CONCEPTRONIC_CTVDIGRCU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		&af9015_props, "Conceptronic USB2.0 DVB-T CTVDIGRCU V3.0", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_MC810,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		&af9015_props, "KWorld Digital MC-810", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	{ DVB_USB_DEVICE(USB_VID_KYE, USB_PID_GENIUS_TVGO_DVB_T03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		&af9015_props, "Genius TVGo DVB-T03", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		&af9015_props, "KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 		&af9015_props, "KWorld PlusTV DVB-T PCI Pro Card (DVB-T PC160-T)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		&af9015_props, "Sveon STV20 Tuner USB DVB-T HDTV", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 		&af9015_props, "DigitalNow TinyTwin v2", RC_MAP_DIGITALNOW_TINYTWIN) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	{ DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		&af9015_props, "Leadtek WinFast DTV2000DS", RC_MAP_LEADTEK_Y04G0051) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		&af9015_props, "KWorld USB DVB-T Stick Mobile (UB383-T)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 		&af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		&af9015_props, "AverMedia AVerTV Volar M (A815Mac)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	{ DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 		&af9015_props, "TerraTec Cinergy T Stick RC", RC_MAP_TERRATEC_SLIM_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	/* XXX: that same ID [0ccd:0099] is used by af9035 driver too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	{ DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		&af9015_props, "TerraTec Cinergy T Stick Dual RC", RC_MAP_TERRATEC_SLIM) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	{ DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		&af9015_props, "AverMedia AVerTV Red HD+ (A850T)", NULL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	{ DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TINYTWIN_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		&af9015_props, "DigitalNow TinyTwin v3", RC_MAP_DIGITALNOW_TINYTWIN) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	{ DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		&af9015_props, "Sveon STV22 Dual USB DVB-T Tuner HDTV", RC_MAP_MSI_DIGIVOX_III) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) MODULE_DEVICE_TABLE(usb, af9015_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) /* usb specific object needed to register this driver with the usb subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) static struct usb_driver af9015_usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	.id_table = af9015_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	.probe = dvb_usbv2_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	.disconnect = dvb_usbv2_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	.suspend = dvb_usbv2_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	.resume = dvb_usbv2_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	.reset_resume = dvb_usbv2_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	.no_dynamic_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	.soft_unbind = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) module_usb_driver(af9015_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) MODULE_DESCRIPTION("Afatech AF9015 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) MODULE_FIRMWARE(AF9015_FIRMWARE);