Ejemplo n.º 1
0
Archivo: dst.c Proyecto: 020gzh/linux
int write_dst(struct dst_state *state, u8 *data, u8 len)
{
	struct i2c_msg msg = {
		.addr = state->config->demod_address,
		.flags = 0,
		.buf = data,
		.len = len
	};

	int err;
	u8 cnt, i;

	dprintk(verbose, DST_NOTICE, 0, "writing [ ");
	for (i = 0; i < len; i++)
		dprintk(verbose, DST_NOTICE, 0, "%02x ", data[i]);
	dprintk(verbose, DST_NOTICE, 0, "]\n");

	for (cnt = 0; cnt < 2; cnt++) {
		if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
			dprintk(verbose, DST_INFO, 1, "_write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, data[0]);
			dst_error_recovery(state);
			continue;
		} else
			break;
	}
	if (cnt >= 2) {
		dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
		dst_error_bailout(state);

		return -1;
	}

	return 0;
}
EXPORT_SYMBOL(write_dst);

int read_dst(struct dst_state *state, u8 *ret, u8 len)
{
	struct i2c_msg msg = {
		.addr = state->config->demod_address,
		.flags = I2C_M_RD,
		.buf = ret,
		.len = len
	};

	int err;
	int cnt;

	for (cnt = 0; cnt < 2; cnt++) {
		if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
			dprintk(verbose, DST_INFO, 1, "read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, ret[0]);
			dst_error_recovery(state);
			continue;
		} else
			break;
	}
	if (cnt >= 2) {
		dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
		dst_error_bailout(state);

		return -1;
	}
	dprintk(verbose, DST_DEBUG, 1, "reply is 0x%x", ret[0]);
	for (err = 1; err < len; err++)
		dprintk(verbose, DST_DEBUG, 0, " 0x%x", ret[err]);
	if (err > 1)
		dprintk(verbose, DST_DEBUG, 0, "\n");

	return 0;
}
EXPORT_SYMBOL(read_dst);

static int dst_set_polarization(struct dst_state *state)
{
	switch (state->voltage) {
	case SEC_VOLTAGE_13:	/*	Vertical	*/
		dprintk(verbose, DST_INFO, 1, "Polarization=[Vertical]");
		state->tx_tuna[8] &= ~0x40;
		break;
	case SEC_VOLTAGE_18:	/*	Horizontal	*/
		dprintk(verbose, DST_INFO, 1, "Polarization=[Horizontal]");
		state->tx_tuna[8] |= 0x40;
		break;
	case SEC_VOLTAGE_OFF:
		break;
	}

	return 0;
}

static int dst_set_freq(struct dst_state *state, u32 freq)
{
	state->frequency = freq;
	dprintk(verbose, DST_INFO, 1, "set Frequency %u", freq);

	if (state->dst_type == DST_TYPE_IS_SAT) {
		freq = freq / 1000;
		if (freq < 950 || freq > 2150)
			return -EINVAL;
		state->tx_tuna[2] = (freq >> 8);
		state->tx_tuna[3] = (u8) freq;
		state->tx_tuna[4] = 0x01;
		state->tx_tuna[8] &= ~0x04;
		if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
			if (freq < 1531)
				state->tx_tuna[8] |= 0x04;
		}
	} else if (state->dst_type == DST_TYPE_IS_TERR) {
Ejemplo n.º 2
0
static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg)
{
	struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
	struct dst_state* state = (struct dst_state*) dvbdev->priv;
	struct ca_slot_info *p_ca_slot_info;
	struct ca_caps *p_ca_caps;
	struct ca_msg *p_ca_message;
	void __user *arg = (void __user *)ioctl_arg;
	int result = 0;

	if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
		dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
		return -ENOMEM;
	}
	if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
		dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
		return -ENOMEM;
	}
	if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
		dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure");
		return -ENOMEM;
	}
	/*	We have now only the standard ioctl's, the driver is upposed to handle internals.	*/
	switch (cmd) {
	case CA_SEND_MSG:
		dprintk(verbose, DST_CA_INFO, 1, " Sending message");
		if ((ca_send_message(state, p_ca_message, arg)) < 0) {
			dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !");
			result = -1;
			goto free_mem_and_exit;
		}
		break;
	case CA_GET_MSG:
		dprintk(verbose, DST_CA_INFO, 1, " Getting message");
		if ((ca_get_message(state, p_ca_message, arg)) < 0) {
			dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !");
			result = -1;
			goto free_mem_and_exit;
		}
		dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !");
		break;
	case CA_RESET:
		dprintk(verbose, DST_CA_ERROR, 1, " Resetting DST");
		dst_error_bailout(state);
		msleep(4000);
		break;
	case CA_GET_SLOT_INFO:
		dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info");
		if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) {
			dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !");
			result = -1;
			goto free_mem_and_exit;
		}
		dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !");
		break;
	case CA_GET_CAP:
		dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities");
		if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) {
			dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !");
			result = -1;
			goto free_mem_and_exit;
		}
		dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !");
		break;
	case CA_GET_DESCR_INFO:
		dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description");
		if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) {
			dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !");
			result = -1;
			goto free_mem_and_exit;
		}
		dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !");
		break;
	case CA_SET_DESCR:
		dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler");
		if ((ca_set_slot_descr()) < 0) {
			dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !");
			result = -1;
			goto free_mem_and_exit;
		}
		dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !");
		break;
	case CA_SET_PID:
		dprintk(verbose, DST_CA_INFO, 1, " Setting PID");
		if ((ca_set_pid()) < 0) {
			dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !");
			result = -1;
			goto free_mem_and_exit;
		}
		dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !");
	default:
		result = -EOPNOTSUPP;
	};
 free_mem_and_exit:
	kfree (p_ca_message);
	kfree (p_ca_slot_info);
	kfree (p_ca_caps);

	return result;
}