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 Anysee E30 DVB-C & 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)  * TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * - add smart card reader support for Conditional Access (CA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Card reader in Anysee is nothing more than ISO 7816 card reader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * There is no hardware CAM in any Anysee device sold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * In my understanding it should be implemented by making own module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * module registers serial interface that can be used to communicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * with any ISO 7816 smart card.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * Any help according to implement serial smart card reader support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * is highly welcome!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include "anysee.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include "dvb-pll.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include "tda1002x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include "mt352.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include "mt352_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include "zl10353.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include "tda18212.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include "cx24116.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include "stv0900.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include "stv6110.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include "isl6423.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include "cxd2820r.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) static int anysee_ctrl_msg(struct dvb_usb_device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 		u8 *sbuf, u8 slen, u8 *rbuf, u8 rlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	int act_len, ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	mutex_lock(&d->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	memcpy(&state->buf[0], sbuf, slen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	state->buf[60] = state->seq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, state->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	/* We need receive one message more after dvb_usb_generic_rw due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	   to weird transaction flow, which is 1 x send + 2 x receive. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	ret = dvb_usbv2_generic_rw_locked(d, state->buf, sizeof(state->buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 			state->buf, sizeof(state->buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 		goto error_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	/* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	 * (EPIPE, Broken pipe). Function supports currently msleep() as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	 * parameter but I would not like to use it, since according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	 * Documentation/timers/timers-howto.rst it should not be used such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	 * short, under < 20ms, sleeps. Repeating failed message would be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	 * better choice as not to add unwanted delays...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	 * Fixing that correctly is one of those or both;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	 * 1) use repeat if possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	 * 2) add suitable delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	/* get answer, retry few times if error returned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 		/* receive 2nd answer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 				d->props->generic_bulk_ctrl_endpoint),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 				state->buf, sizeof(state->buf), &act_len, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 			dev_dbg(&d->udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 					"%s: recv bulk message failed=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 					__func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 			dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 					rlen, state->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 			if (state->buf[63] != 0x4f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 				dev_dbg(&d->udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 						"%s: cmd failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 			break;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 		/* all retries failed, it is fatal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 		dev_err(&d->udev->dev, "%s: recv bulk message failed=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 				KBUILD_MODNAME, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 		goto error_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	/* read request, copy returned data to return buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	if (rbuf && rlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 		memcpy(rbuf, state->buf, rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) error_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	mutex_unlock(&d->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, *val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) /* write single register with mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	u8 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	u8 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	/* no need for read if whole reg is written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	if (mask != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		ret = anysee_read_reg(d, reg, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		val &= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		tmp &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		val |= tmp;
^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) 	return anysee_write_reg(d, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) /* read single register with mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	u8 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	u8 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	ret = anysee_read_reg(d, reg, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	tmp &= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	/* find position of the first bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 		if ((mask >> i) & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	*val = tmp >> i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	return 0;
^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) static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	u8 buf[] = {CMD_GET_HW_INFO};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static int anysee_streaming_ctrl(struct dvb_frontend *fe, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	dev_dbg(&fe_to_d(fe)->udev->dev, "%s: onoff=%d\n", __func__, onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	return anysee_ctrl_msg(fe_to_d(fe), buf, sizeof(buf), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	dev_dbg(&d->udev->dev, "%s: state=%d interval=%d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 			mode, interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) /* I2C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	int ret = 0, inc, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	while (i < num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 			if (msg[i].len > 2 || msg[i+1].len > 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 				ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 			buf[0] = CMD_I2C_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			buf[1] = (msg[i].addr << 1) | 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 			buf[2] = msg[i].buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 			buf[3] = msg[i].buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 			buf[4] = msg[i].len-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 			buf[5] = msg[i+1].len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 			ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 				msg[i+1].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 			inc = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 			if (msg[i].len > 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 				ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 			buf[0] = CMD_I2C_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 			buf[1] = (msg[i].addr << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 			buf[2] = msg[i].len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 			buf[3] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 			memcpy(&buf[4], msg[i].buf, msg[i].len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 			ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 			inc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		i += inc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	mutex_unlock(&d->i2c_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	return ret ? ret : i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) static u32 anysee_i2c_func(struct i2c_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	return I2C_FUNC_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) static struct i2c_algorithm anysee_i2c_algo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	.master_xfer   = anysee_master_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	.functionality = anysee_i2c_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) static int anysee_mt352_demod_init(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	static u8 clock_config[]   = { CLOCK_CTL,  0x38, 0x28 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	static u8 reset[]          = { RESET,      0x80 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	static u8 adc_ctl_1_cfg[]  = { ADC_CTL_1,  0x40 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	static u8 agc_cfg[]        = { AGC_TARGET, 0x28, 0x20 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	static u8 gpp_ctl_cfg[]    = { GPP_CTL,    0x33 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	mt352_write(fe, clock_config,   sizeof(clock_config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	udelay(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	mt352_write(fe, reset,          sizeof(reset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) /* Callbacks for DVB USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) static struct tda10023_config anysee_tda10023_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	.demod_address = (0x1a >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	.invert = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	.xtal   = 16000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	.pll_m  = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	.pll_p  = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	.pll_n  = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	.output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	.deltaf = 0xfeeb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) static struct mt352_config anysee_mt352_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	.demod_address = (0x1e >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	.demod_init    = anysee_mt352_demod_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) static struct zl10353_config anysee_zl10353_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	.demod_address = (0x1e >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	.parallel_ts = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) static struct zl10353_config anysee_zl10353_tda18212_config2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	.demod_address = (0x1e >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	.parallel_ts = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	.disable_i2c_gate_ctrl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	.no_tuner = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	.if2 = 41500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) static struct zl10353_config anysee_zl10353_tda18212_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	.demod_address = (0x18 >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	.parallel_ts = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	.disable_i2c_gate_ctrl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	.no_tuner = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	.if2 = 41500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) static struct tda10023_config anysee_tda10023_tda18212_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	.demod_address = (0x1a >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	.xtal   = 16000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	.pll_m  = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	.pll_p  = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	.pll_n  = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	.output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	.deltaf = 0xba02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) static const struct tda18212_config anysee_tda18212_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	.if_dvbt_6 = 4150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	.if_dvbt_7 = 4150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	.if_dvbt_8 = 4150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	.if_dvbc = 5000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) static const struct tda18212_config anysee_tda18212_config2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	.if_dvbt_6 = 3550,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	.if_dvbt_7 = 3700,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	.if_dvbt_8 = 4150,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	.if_dvbt2_6 = 3250,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	.if_dvbt2_7 = 4000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	.if_dvbt2_8 = 4000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	.if_dvbc = 5000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) static struct cx24116_config anysee_cx24116_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	.demod_address = (0xaa >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	.mpg_clk_pos_pol = 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	.i2c_wr_max = 48,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) static struct stv0900_config anysee_stv0900_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	.demod_address = (0xd0 >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	.demod_mode = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	.xtal = 8000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	.clkmode = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	.diseqc_mode = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	.tun1_maddress = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	.tun1_adc = 1, /* 1 Vpp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	.path1_mode = 3,
^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) static struct stv6110_config anysee_stv6110_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	.i2c_address = (0xc0 >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	.mclk = 16000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	.clk_div = 1,
^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) static struct isl6423_config anysee_isl6423_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	.current_max = SEC_CURRENT_800m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	.curlim  = SEC_CURRENT_LIM_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	.mod_extern = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	.addr = (0x10 >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) static struct cxd2820r_config anysee_cxd2820r_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	.i2c_address = 0x6d, /* (0xda >> 1) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	.ts_mode = 0x38,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374)  * New USB device strings: Mfr=1, Product=2, SerialNumber=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375)  * Manufacturer: AMT.CO.KR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377)  * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)  * PCB: ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  * parts: DNOS404ZH102A(MT352, DTT7579(?))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381)  * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382)  * PCB: PCB 507T (rev1.61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383)  * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)  * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385)  * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387)  * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388)  * PCB: 507CD (rev1.1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389)  * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390)  * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391)  * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392)  * IOD[0] ZL10353 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393)  * IOA[7] TS 0=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394)  * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396)  * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397)  * PCB: 507DC (rev0.2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398)  * parts: TDA10023, DTOS403IH102B TM, CST56I01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399)  * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400)  * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)  * IOD[0] TDA10023 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)  * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)  * PCB: 507SI (rev2.1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  * IOD[0] CX24116 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  * PCB: 507FA (rev0.4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  * parts: TDA10023, DTOS403IH102B TM, TDA8024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  * IOD[5] TDA10023 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)  * IOE[0] tuner 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  * PCB: 507FA (rev1.1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)  * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)  * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422)  * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423)  * DVB-C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424)  * IOD[5] TDA10023 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425)  * IOE[0] tuner 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426)  * DVB-T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427)  * IOD[0] ZL10353 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428)  * IOE[0] tuner 0=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429)  * tuner is behind ZL10353 I2C-gate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430)  * tuner is behind TDA10023 I2C-gate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432)  * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433)  * PCB: 508TC (rev0.6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434)  * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435)  * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436)  * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437)  * IOA[7] TS 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438)  * IOE[4] TDA18212 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439)  * DVB-C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440)  * IOD[6] ZL10353 0=disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441)  * IOD[5] TDA10023 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442)  * IOE[0] IF 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443)  * DVB-T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444)  * IOD[5] TDA10023 0=disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445)  * IOD[6] ZL10353 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446)  * IOE[0] IF 0=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448)  * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449)  * PCB: 508S2 (rev0.7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)  * parts: DNBU10512IST(STV0903, STV6110), ISL6423
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)  * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  * IOA[7] TS 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454)  * IOE[5] STV0903 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456)  * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457)  * PCB: 508T2C (rev0.3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458)  * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459)  * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460)  * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461)  * IOA[7] TS 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462)  * IOE[5] CXD2820R 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464)  * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)  * PCB: 508PTC (rev0.5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466)  * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)  * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468)  * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469)  * IOA[7] TS 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470)  * IOE[4] TDA18212 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471)  * DVB-C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472)  * IOD[6] ZL10353 0=disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473)  * IOD[5] TDA10023 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474)  * IOE[0] IF 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475)  * DVB-T:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476)  * IOD[5] TDA10023 0=disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477)  * IOD[6] ZL10353 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478)  * IOE[0] IF 0=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)  * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)  * PCB: 508PS2 (rev0.4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)  * parts: DNBU10512IST(STV0903, STV6110), ISL6423
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)  * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485)  * IOA[7] TS 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486)  * IOE[5] STV0903 1=enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) static int anysee_read_config(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	u8 hw_info[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	 * Check which hardware we have.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	 * We must do this call two times to get reliable values (hw/fw bug).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	ret = anysee_get_hw_info(d, hw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	ret = anysee_get_hw_info(d, hw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	 * Meaning of these info bytes are guessed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	dev_info(&d->udev->dev, "%s: firmware version %d.%d hardware id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			KBUILD_MODNAME, hw_info[1], hw_info[2], hw_info[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	state->hw = hw_info[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) /* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	/* enable / disable tuner access on IOE[4] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	return anysee_wr_reg_mask(fe_to_d(fe), REG_IOE, (enable << 4), 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	struct anysee_state *state = fe_to_priv(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	struct dvb_usb_device *d = fe_to_d(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	/* no frontend sleep control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	if (onoff == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	switch (state->hw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	case ANYSEE_HW_507FA: /* 15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		/* E30 Combo Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		/* E30 C Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		if (fe->id == 0)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 			/* disable DVB-T demod on IOD[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			/* enable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 			ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 			/* enable DVB-C tuner on IOE[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 			/* disable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 			ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 			/* enable DVB-T demod on IOD[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 			ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 			/* enable DVB-T tuner on IOE[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 			ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	case ANYSEE_HW_508TC: /* 18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	case ANYSEE_HW_508PTC: /* 21 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		/* E7 TC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		/* E7 PTC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		if (fe->id == 0)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 			/* disable DVB-T demod on IOD[6] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 			ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			/* enable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 			ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 			/* enable IF route on IOE[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 			ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			/* disable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			/* enable DVB-T demod on IOD[6] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			/* enable IF route on IOE[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) static int anysee_add_i2c_dev(struct dvb_usb_device *d, const char *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		u8 addr, void *platform_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	int ret, num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	struct i2c_adapter *adapter = &d->i2c_adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	struct i2c_board_info board_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		.addr = addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		.platform_data = platform_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	strscpy(board_info.type, type, I2C_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	/* find first free client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	for (num = 0; num < ANYSEE_I2C_CLIENT_MAX; num++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		if (state->i2c_client[num] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	if (num == ANYSEE_I2C_CLIENT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		dev_err(&d->udev->dev, "%s: I2C client out of index\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 				KBUILD_MODNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	request_module("%s", board_info.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	/* register I2C device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	client = i2c_new_client_device(adapter, &board_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (!i2c_client_has_driver(client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		goto err;
^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) 	/* increase I2C driver usage count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	if (!try_module_get(client->dev.driver->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		i2c_unregister_device(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		goto err;
^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) 	state->i2c_client[num] = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) static void anysee_del_i2c_dev(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	/* find last used client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	num = ANYSEE_I2C_CLIENT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	while (num--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		if (state->i2c_client[num] != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	if (num == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		dev_err(&d->udev->dev, "%s: I2C client out of index\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 				KBUILD_MODNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	client = state->i2c_client[num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	/* decrease I2C driver usage count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	module_put(client->dev.driver->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	/* unregister I2C device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	i2c_unregister_device(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	state->i2c_client[num] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	dev_dbg(&d->udev->dev, "%s: failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	struct anysee_state *state = adap_to_priv(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	struct dvb_usb_device *d = adap_to_d(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	u8 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	struct i2c_msg msg[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 			.addr = 0x60,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 			.flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 			.len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			.buf = "\x00",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			.addr = 0x60,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			.flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 			.len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 			.buf = &tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	switch (state->hw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	case ANYSEE_HW_507T: /* 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		/* E30 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		adap->fe[0] = dvb_attach(mt352_attach, &anysee_mt352_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 				&d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		if (adap->fe[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 				&d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	case ANYSEE_HW_507CD: /* 6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		/* E30 Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		/* enable DVB-T demod on IOD[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		/* enable transport stream on IOA[7] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 				&d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	case ANYSEE_HW_507DC: /* 10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		/* E30 C Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		/* enable DVB-C demod on IOD[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		adap->fe[0] = dvb_attach(tda10023_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 				&anysee_tda10023_config, &d->i2c_adap, 0x48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	case ANYSEE_HW_507SI: /* 11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		/* E30 S2 Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		/* enable DVB-S/S2 demod on IOD[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		adap->fe[0] = dvb_attach(cx24116_attach, &anysee_cx24116_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 				&d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	case ANYSEE_HW_507FA: /* 15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		/* E30 Combo Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		/* E30 C Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		/* enable tuner on IOE[4] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 4), 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		/* probe TDA18212 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		ret = i2c_transfer(&d->i2c_adap, msg, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		if (ret == 2 && tmp == 0xc7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			dev_dbg(&d->udev->dev, "%s: TDA18212 found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 					__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			state->has_tda18212 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		/* disable tuner on IOE[4] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 4), 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		/* disable DVB-T demod on IOD[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		/* enable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		if (tmp == 0xc7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 			/* TDA18212 config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 			adap->fe[0] = dvb_attach(tda10023_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 					&anysee_tda10023_tda18212_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 					&d->i2c_adap, 0x48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			/* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			if (adap->fe[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 				adap->fe[0]->ops.i2c_gate_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 						anysee_i2c_gate_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			/* PLL config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			adap->fe[0] = dvb_attach(tda10023_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 					&anysee_tda10023_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 					&d->i2c_adap, 0x48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		/* break out if first frontend attaching fails */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		if (!adap->fe[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		/* disable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		/* enable DVB-T demod on IOD[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		if (tmp == 0xc7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 			/* TDA18212 config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			adap->fe[1] = dvb_attach(zl10353_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 					&anysee_zl10353_tda18212_config2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 					&d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			/* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 			if (adap->fe[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 				adap->fe[1]->ops.i2c_gate_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 						anysee_i2c_gate_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			/* PLL config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			adap->fe[1] = dvb_attach(zl10353_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 					&anysee_zl10353_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 					&d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	case ANYSEE_HW_508TC: /* 18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	case ANYSEE_HW_508PTC: /* 21 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		/* E7 TC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		/* E7 PTC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		/* disable DVB-T demod on IOD[6] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		/* enable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		adap->fe[0] = dvb_attach(tda10023_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 				&anysee_tda10023_tda18212_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 				&d->i2c_adap, 0x48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		/* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		if (adap->fe[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			adap->fe[0]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		/* break out if first frontend attaching fails */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		if (!adap->fe[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		/* disable DVB-C demod on IOD[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		/* enable DVB-T demod on IOD[6] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		adap->fe[1] = dvb_attach(zl10353_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 				&anysee_zl10353_tda18212_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 				&d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		/* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		if (adap->fe[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 			adap->fe[1]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		state->has_ci = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	case ANYSEE_HW_508S2: /* 19 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	case ANYSEE_HW_508PS2: /* 22 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		/* E7 S2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		/* E7 PS2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		/* enable DVB-S/S2 demod on IOE[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		adap->fe[0] = dvb_attach(stv0900_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 				&anysee_stv0900_config, &d->i2c_adap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		state->has_ci = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	case ANYSEE_HW_508T2C: /* 20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		/* E7 T2C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		/* enable DVB-T/T2/C demod on IOE[5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		/* attach demod */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		adap->fe[0] = dvb_attach(cxd2820r_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 				&anysee_cxd2820r_config, &d->i2c_adap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		state->has_ci = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	if (!adap->fe[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		/* we have no frontend :-( */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		dev_err(&d->udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 				"%s: Unsupported Anysee version. Please report to <linux-media@vger.kernel.org>.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 				KBUILD_MODNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	struct anysee_state *state = adap_to_priv(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	struct dvb_usb_device *d = adap_to_d(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	struct dvb_frontend *fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	dev_dbg(&d->udev->dev, "%s:\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	switch (state->hw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	case ANYSEE_HW_507T: /* 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		/* E30 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		/* attach tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1), NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 				DVB_PLL_THOMSON_DTT7579);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	case ANYSEE_HW_507CD: /* 6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		/* E30 Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		/* attach tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 				&d->i2c_adap, DVB_PLL_THOMSON_DTT7579);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	case ANYSEE_HW_507DC: /* 10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		/* E30 C Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		/* attach tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 				&d->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	case ANYSEE_HW_507SI: /* 11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		/* E30 S2 Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		/* attach LNB controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		fe = dvb_attach(isl6423_attach, adap->fe[0], &d->i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 				&anysee_isl6423_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	case ANYSEE_HW_507FA: /* 15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		/* E30 Combo Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		/* E30 C Plus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		/* Try first attach TDA18212 silicon tuner on IOE[4], if that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		 * fails attach old simple PLL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		/* attach tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		if (state->has_tda18212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 			struct tda18212_config tda18212_config =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 					anysee_tda18212_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 			tda18212_config.fe = adap->fe[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			ret = anysee_add_i2c_dev(d, "tda18212", 0x60,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 					&tda18212_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 			/* copy tuner ops for 2nd FE as tuner is shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			if (adap->fe[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 				adap->fe[1]->tuner_priv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 						adap->fe[0]->tuner_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				memcpy(&adap->fe[1]->ops.tuner_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 						&adap->fe[0]->ops.tuner_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 						sizeof(struct dvb_tuner_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 			/* attach tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			fe = dvb_attach(dvb_pll_attach, adap->fe[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 					(0xc0 >> 1), &d->i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 					DVB_PLL_SAMSUNG_DTOS403IH102A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			if (fe && adap->fe[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 				/* attach tuner for 2nd FE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 				fe = dvb_attach(dvb_pll_attach, adap->fe[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 						(0xc0 >> 1), &d->i2c_adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 						DVB_PLL_SAMSUNG_DTOS403IH102A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	case ANYSEE_HW_508TC: /* 18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	case ANYSEE_HW_508PTC: /* 21 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		/* E7 TC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		/* E7 PTC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		struct tda18212_config tda18212_config = anysee_tda18212_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		tda18212_config.fe = adap->fe[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		ret = anysee_add_i2c_dev(d, "tda18212", 0x60, &tda18212_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		/* copy tuner ops for 2nd FE as tuner is shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		if (adap->fe[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 			adap->fe[1]->tuner_priv = adap->fe[0]->tuner_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			memcpy(&adap->fe[1]->ops.tuner_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 					&adap->fe[0]->ops.tuner_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 					sizeof(struct dvb_tuner_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	case ANYSEE_HW_508S2: /* 19 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	case ANYSEE_HW_508PS2: /* 22 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		/* E7 S2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		/* E7 PS2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		/* attach tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		fe = dvb_attach(stv6110_attach, adap->fe[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 				&anysee_stv6110_config, &d->i2c_adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		if (fe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 			/* attach LNB controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 			fe = dvb_attach(isl6423_attach, adap->fe[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 					&d->i2c_adap, &anysee_isl6423_config);
^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) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	case ANYSEE_HW_508T2C: /* 20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		/* E7 T2C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		struct tda18212_config tda18212_config =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 				anysee_tda18212_config2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		tda18212_config.fe = adap->fe[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		ret = anysee_add_i2c_dev(d, "tda18212", 0x60, &tda18212_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		fe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	if (fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) #if IS_ENABLED(CONFIG_RC_CORE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) static int anysee_rc_query(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	u8 buf[] = {CMD_GET_IR_CODE};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	u8 ircode[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	/* Remote controller is basic NEC using address byte 0x08.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	   Anysee device RC query returns only two bytes, status and code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	   address byte is dropped. Also it does not return any value for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	   NEC RCs having address byte other than 0x08. Due to that, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	   cannot use that device as standard NEC receiver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	   It could be possible make hack which reads whole code directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	   from device memory... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	if (ircode[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		dev_dbg(&d->udev->dev, "%s: key pressed %02x\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 				ircode[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		rc_keydown(d->rc_dev, RC_PROTO_NEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 			   RC_SCANCODE_NEC(0x08, ircode[1]), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	return 0;
^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) static int anysee_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	rc->allowed_protos = RC_PROTO_BIT_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	rc->query          = anysee_rc_query;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	rc->interval       = 250;  /* windows driver uses 500ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	#define anysee_get_rc_config NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	int addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	return val;
^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) static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	int addr, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	u8 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	u8 addr, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	state->ci_cam_ready = jiffies + msecs_to_jiffies(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	msleep(300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	msleep(30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	int open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	struct dvb_usb_device *d = ci->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	u8 tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	if (tmp == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		ret = DVB_CA_EN50221_POLL_CAM_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		if (time_after(jiffies, state->ci_cam_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 			ret |= DVB_CA_EN50221_POLL_CAM_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) static int anysee_ci_init(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	state->ci.owner               = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	state->ci.read_attribute_mem  = anysee_ci_read_attribute_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	state->ci.write_attribute_mem = anysee_ci_write_attribute_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	state->ci.read_cam_control    = anysee_ci_read_cam_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	state->ci.write_cam_control   = anysee_ci_write_cam_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	state->ci.slot_reset          = anysee_ci_slot_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	state->ci.slot_shutdown       = anysee_ci_slot_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	state->ci.slot_ts_enable      = anysee_ci_slot_ts_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	state->ci.poll_slot_status    = anysee_ci_poll_slot_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	state->ci.data                = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	if (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) 	ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	state->ci_attached = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) static void anysee_ci_release(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	/* detach CI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	if (state->ci_attached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		dvb_ca_en50221_release(&state->ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) static int anysee_init(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	/* There is one interface with two alternate settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	   Alternate setting 0 is for bulk transfer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	   Alternate setting 1 is for isochronous transfer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	   We use bulk transfer (alternate setting 0). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	ret = usb_set_interface(d->udev, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	/* LED light */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	ret = anysee_led_ctrl(d, 0x01, 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	/* enable IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	ret = anysee_ir_ctrl(d, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	/* attach CI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	if (state->has_ci) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		ret = anysee_ci_init(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) static void anysee_exit(struct dvb_usb_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	struct anysee_state *state = d_to_priv(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	if (state->i2c_client[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		anysee_del_i2c_dev(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	return anysee_ci_release(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) /* DVB USB Driver stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static struct dvb_usb_device_properties anysee_props = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	.driver_name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	.adapter_nr = adapter_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	.size_of_priv = sizeof(struct anysee_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	.generic_bulk_ctrl_endpoint = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	.generic_bulk_ctrl_endpoint_response = 0x81,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	.i2c_algo         = &anysee_i2c_algo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	.read_config      = anysee_read_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	.frontend_attach  = anysee_frontend_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	.tuner_attach     = anysee_tuner_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	.init             = anysee_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	.get_rc_config    = anysee_get_rc_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	.frontend_ctrl    = anysee_frontend_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	.streaming_ctrl   = anysee_streaming_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	.exit             = anysee_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	.num_adapters = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	.adapter = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 			.stream = DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	}
^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) static const struct usb_device_id anysee_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	{ DVB_USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		&anysee_props, "Anysee", RC_MAP_ANYSEE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	{ DVB_USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		&anysee_props, "Anysee", RC_MAP_ANYSEE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) MODULE_DEVICE_TABLE(usb, anysee_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) static struct usb_driver anysee_usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	.id_table = anysee_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	.probe = dvb_usbv2_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	.disconnect = dvb_usbv2_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	.suspend = dvb_usbv2_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	.resume = dvb_usbv2_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	.reset_resume = dvb_usbv2_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	.no_dynamic_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	.soft_unbind = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) module_usb_driver(anysee_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) MODULE_LICENSE("GPL");