Commit b7d425d3 authored by Malcolm Priestley's avatar Malcolm Priestley Committed by Mauro Carvalho Chehab
Browse files

[media] it913x Support it9135 Verions 2 chip



Support for version 2 type chips and other LNA versions of version 1

Scripts may be compressed slightly at a later stage.

TODO
Firmware loader
However, things are a little confusing,  it is not clear that
dvb-usb-it9137-01.fw does not work with version 2 chips
as in recent files both firmwares are the same.

Should be applied to: 8133 Support for single ITE 9135 device.

Signed-off-by: default avatarMalcolm Priestley <tvboxspy@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ead32d53
Loading
Loading
Loading
Loading
+15 −37
Original line number Diff line number Diff line
@@ -60,15 +60,6 @@ struct it913x_state {
	u8 id;
};

struct ite_config {
	u8 chip_ver;
	u16 chip_type;
	u32 firmware;
	u8 tuner_id_0;
	u8 tuner_id_1;
	u8 dual_mode;
};

struct ite_config it913x_config;

static int it913x_bulk_write(struct usb_device *dev,
@@ -390,8 +381,8 @@ static int it913x_identify_state(struct usb_device *udev,
			if (ret != 0)
				ret = it913x_wr_reg(udev, DEV_0,
					GPIOH1_O, 0x0);
		}
			props->num_adapters = 2;
		}
	} else
		props->num_adapters = 1;

@@ -474,13 +465,18 @@ static int it913x_download_firmware(struct usb_device *udev,
	/* Tuner function */
	if (it913x_config.dual_mode)
		ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
	else
		ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0x68);

	if ((it913x_config.chip_ver == 1) &&
		(it913x_config.chip_type == 0x9135)) {
		ret |= it913x_wr_reg(udev, DEV_0,  PADODPU, 0x0);
		ret |= it913x_wr_reg(udev, DEV_0,  AGC_O_D, 0x0);
		if (it913x_config.dual_mode) {
			ret |= it913x_wr_reg(udev, DEV_1,  PADODPU, 0x0);
			ret |= it913x_wr_reg(udev, DEV_1,  AGC_O_D, 0x0);
		}
	}

	return (ret < 0) ? -ENODEV : 0;
}
@@ -501,31 +497,13 @@ static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct usb_device *udev = adap->dev->udev;
	int ret = 0;
	u8 adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);
	u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
	u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize;
	u8 tuner_id, tuner_type;

	if (adap->id == 0)
		tuner_id = it913x_config.tuner_id_0;
	else
		tuner_id = it913x_config.tuner_id_1;

	/* TODO we always use IT9137 possible references here*/
	/* Documentation suggests don't care */
	switch (tuner_id) {
	case 0x51:
	case 0x52:
	case 0x60:
	case 0x61:
	case 0x62:
	default:
	case 0x38:
		tuner_type = IT9137;
	}
	it913x_config.adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);

	adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach,
		&adap->dev->i2c_adap, adap_addr, adf, tuner_type);
		&adap->dev->i2c_adap, adap_addr, &it913x_config);

	if (adap->id == 0 && adap->fe_adap[0].fe) {
		ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1);
@@ -698,5 +676,5 @@ module_exit(it913x_module_exit);

MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
MODULE_DESCRIPTION("it913x USB 2 Driver");
MODULE_VERSION("1.07");
MODULE_VERSION("1.08");
MODULE_LICENSE("GPL");
+705 −13

File changed.

Preview size limit exceeded, changes collapsed.

+82 −28
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
struct it913x_fe_state {
	struct dvb_frontend frontend;
	struct i2c_adapter *i2c_adap;
	struct ite_config *config;
	u8 i2c_addr;
	u32 frequency;
	u8 adf;
@@ -211,6 +212,9 @@ static int it913x_init_tuner(struct it913x_fe_state *state)
	state->tun_fn_min /= (state->tun_fdiv * nv_val);
	deb_info("Tuner fn_min %d", state->tun_fn_min);

	if (state->config->chip_ver > 1)
		msleep(50);
	else {
		for (i = 0; i < 50; i++) {
			reg = it913x_read_reg_u8(state, 0xec82);
			if (reg > 0)
@@ -219,6 +223,7 @@ static int it913x_init_tuner(struct it913x_fe_state *state)
				return -ENODEV;
			udelay(2000);
		}
	}

	return it913x_write_reg(state, PRO_DMOD, 0xed81, val);
}
@@ -578,7 +583,12 @@ static int it913x_fe_set_frontend(struct dvb_frontend *fe,

	deb_info("Frontend Set Tuner Type %02x", state->tuner_type);
	switch (state->tuner_type) {
	case IT9137: /* Tuner type 0x38 */
	case IT9135_38:
	case IT9135_51:
	case IT9135_52:
	case IT9135_60:
	case IT9135_61:
	case IT9135_62:
		ret = it9137_set_tuner(state,
			p->u.ofdm.bandwidth, p->frequency);
		break;
@@ -678,13 +688,14 @@ static u32 compute_div(u32 a, u32 b, u32 x)

static int it913x_fe_start(struct it913x_fe_state *state)
{
	struct it913xset *set_fe;
	struct it913xset *set_lna;
	struct it913xset *set_mode;
	int ret;
	u8 adf = (state->adf & 0xf);
	u8 adf = (state->config->adf & 0xf);
	u32 adc, xtal;
	u8 b[4];

	if (state->config->chip_ver == 1)
		ret = it913x_init_tuner(state);

	if (adf < 12) {
@@ -720,23 +731,57 @@ static int it913x_fe_start(struct it913x_fe_state *state)
	b[1] = (adc >> 8) & 0xff;
	b[2] = (adc >> 16) & 0xff;
	ret |= it913x_write(state, PRO_DMOD, ADC_FREQ, b, 3);
	if (ret < 0)
		return -ENODEV;

	/* v1 or v2 tuner script */
	if (state->config->chip_ver > 1)
		ret = it913x_fe_script_loader(state, it9135_v2);
	else
		ret = it913x_fe_script_loader(state, it9135_v1);
	if (ret < 0)
		return ret;

	/* LNA Scripts */
	switch (state->tuner_type) {
	case IT9137: /* Tuner type 0x38 */
		set_fe = it9137_set;
	case IT9135_51:
		set_lna = it9135_51;
		break;
	case IT9135_52:
		set_lna = it9135_52;
		break;
	case IT9135_60:
		set_lna = it9135_60;
		break;
	case IT9135_61:
		set_lna = it9135_61;
		break;
	case IT9135_62:
		set_lna = it9135_62;
		break;
	case IT9135_38:
	default:
		return -EINVAL;
		set_lna = it9135_38;
	}
	ret = it913x_fe_script_loader(state, set_lna);
	if (ret < 0)
		return ret;

	if (state->config->chip_ver == 2) {
		ret = it913x_write_reg(state, PRO_DMOD, TRIGGER_OFSM, 0x1);
		ret |= it913x_write_reg(state, PRO_LINK, PADODPU, 0x0);
		ret |= it913x_write_reg(state, PRO_LINK, AGC_O_D, 0x0);
		ret |= it913x_init_tuner(state);
	}
	if (ret < 0)
		return -ENODEV;

	/* set the demod */
	ret = it913x_fe_script_loader(state, set_fe);
	/* Always solo frontend */
	set_mode = set_solo_fe;
	ret |= it913x_fe_script_loader(state, set_mode);

	ret |= it913x_fe_suspend(state);
	return 0;
	return (ret < 0) ? -ENODEV : 0;
}

static int it913x_fe_init(struct dvb_frontend *fe)
@@ -750,13 +795,7 @@ static int it913x_fe_init(struct dvb_frontend *fe)

	ret |= it913x_fe_script_loader(state, init_1);

	switch (state->tuner_type) {
	case IT9137:
	ret |= it913x_write_reg(state, PRO_DMOD, 0xfba8, 0x0);
		break;
	default:
		return -EINVAL;
	}

	return (ret < 0) ? -ENODEV : 0;
}
@@ -770,19 +809,34 @@ static void it913x_fe_release(struct dvb_frontend *fe)
static struct dvb_frontend_ops it913x_fe_ofdm_ops;

struct dvb_frontend *it913x_fe_attach(struct i2c_adapter *i2c_adap,
		u8 i2c_addr, u8 adf, u8 type)
		u8 i2c_addr, struct ite_config *config)
{
	struct it913x_fe_state *state = NULL;
	int ret;

	/* allocate memory for the internal state */
	state = kzalloc(sizeof(struct it913x_fe_state), GFP_KERNEL);
	if (state == NULL)
		return NULL;
	if (config == NULL)
		goto error;

	state->i2c_adap = i2c_adap;
	state->i2c_addr = i2c_addr;
	state->adf = adf;
	state->tuner_type = type;
	state->config = config;

	switch (state->config->tuner_id_0) {
	case IT9135_51:
	case IT9135_52:
	case IT9135_60:
	case IT9135_61:
	case IT9135_62:
		state->tuner_type = state->config->tuner_id_0;
		break;
	default:
	case IT9135_38:
		state->tuner_type = IT9135_38;
	}

	ret = it913x_fe_start(state);
	if (ret < 0)
@@ -835,5 +889,5 @@ static struct dvb_frontend_ops it913x_fe_ofdm_ops = {

MODULE_DESCRIPTION("it913x Frontend and it9137 tuner");
MODULE_AUTHOR("Malcolm Priestley tvboxspy@gmail.com");
MODULE_VERSION("1.07");
MODULE_VERSION("1.08");
MODULE_LICENSE("GPL");
+21 −3
Original line number Diff line number Diff line
@@ -23,13 +23,25 @@

#include <linux/dvb/frontend.h>
#include "dvb_frontend.h"

struct ite_config {
	u8 chip_ver;
	u16 chip_type;
	u32 firmware;
	u8 tuner_id_0;
	u8 tuner_id_1;
	u8 dual_mode;
	u8 adf;
};

#if defined(CONFIG_DVB_IT913X_FE) || (defined(CONFIG_DVB_IT913X_FE_MODULE) && \
defined(MODULE))
extern struct dvb_frontend *it913x_fe_attach(struct i2c_adapter *i2c_adap,
			u8 i2c_addr, u8 adf, u8 type);
			u8 i2c_addr, struct ite_config *config);
#else
static inline struct dvb_frontend *it913x_fe_attach(
		struct i2c_adapter *i2c_adap,	u8 i2c_addr, u8 adf, u8 type)
		struct i2c_adapter *i2c_adap,
			u8 i2c_addr, struct ite_config *config)
{
	printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
	return NULL;
@@ -144,8 +156,14 @@ static inline struct dvb_frontend *it913x_fe_attach(
#define EST_SIGNAL_LEVEL	0x004a
#define FREE_BAND		0x004b
#define SUSPEND_FLAG		0x004c
/* Build in tuners */
/* Build in tuner types */
#define IT9137 0x38
#define IT9135_38 0x38
#define IT9135_51 0x50
#define IT9135_52 0x52
#define IT9135_60 0x60
#define IT9135_61 0x61
#define IT9135_62 0x62

enum {
	CMD_DEMOD_READ = 0,