Ejemplo n.º 1
0
static int sr200pc20_i2c_set_data_burst(struct v4l2_subdev *sd,
					const regs_short_t reg_buffer[],
					u32 num_of_regs)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	u16 subaddr, data_value;
	int i, err = 0;

	for (i = 0; i < num_of_regs; i++) {
		subaddr = reg_buffer[i].subaddr;
		data_value = reg_buffer[i].value;

		switch(subaddr) {
		case DELAY_SEQ:
			debug_msleep(sd, data_value * 10);
			break;
		default:
			err = sr200pc20_i2c_write_byte(client, subaddr, data_value);
			if (unlikely(err < 0)) {
				cam_err("%s: ERROR, failed to"
					"write reg(0x%02X, 0x%02X).err=%d\n",
					__func__, subaddr, data_value, err);
				return -EIO;
			}
			break;
		}
	}

	return 0;
}
Ejemplo n.º 2
0
static inline int sr200pc20_get_iso(struct v4l2_subdev *sd, u16 *iso)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	/* u16 iso_gain_table[] = {10, 18, 23, 28};
	u16 iso_table[] = {0, 50, 100, 200, 400}; */
	u16 read_value = 0, gain = 0;


	sr200pc20_i2c_write_byte(client, 0x03, 0x20);
	sr200pc20_i2c_read_byte(client, 0xb0, &read_value);
	gain = (read_value * 100  / 32) + 50;

	if (read_value < 125)
		*iso = 50;
	else if (read_value < 175)
		*iso = 100;
	else if (read_value < 250)
		*iso = 200;
	else if (read_value < 375)
		*iso = 400;
	else if (read_value < 550)
		*iso = 800;
	else
		*iso = 1600;

	cam_dbg("gain=%d, ISO=%d\n", gain, *iso);

	return 0;
}
Ejemplo n.º 3
0
static int sr200pc20_init_regs(struct v4l2_subdev *sd)
{
	struct sr200pc20_state *state = to_state(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	u16 read_value = 0;
	int err = -ENODEV;

	err = sr200pc20_i2c_write_byte(client, 0x03, 0x00);
	if (unlikely(err < 0))
	{
		/**************************************************************
		 	add by cym 20130222
			because if the device dose not exist the driver also access this struct 
		***************************************************************/
		state->regs = &reg_datas;
		/* end add */
		
		return -ENODEV;
	}

	sr200pc20_i2c_read_byte(client, 0x04, &read_value);
	if (likely(read_value == SR200PC20_CHIP_ID))
		cam_info("Sensor ChipID: 0x%02X\n", SR200PC20_CHIP_ID);
	else
		cam_info("Sensor ChipID: 0x%02X, unknown chipID\n", read_value);

	state->regs = &reg_datas;

	return 0;
}
Ejemplo n.º 4
0
static int sr200pc20_get_iso_speed_rate(struct v4l2_subdev *sd)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	unsigned short read_value;
	int gain;
	int isospeedrating = 0;

	sr200pc20_i2c_write_byte(client, 0x03, 0x20);
	sr200pc20_i2c_read_byte(client, 0xb0, &read_value);
	gain = ((int)read_value * 100  / 32) + 50;

	if (read_value < 125)
		isospeedrating = 50;
	else if (read_value < 175)
		isospeedrating = 100;
	else if (read_value < 250)
		isospeedrating = 200;
	else if (read_value < 375)
		isospeedrating = 400;
	else if (read_value < 550)
		isospeedrating = 800;
	else
		isospeedrating = 1600;

	cam_dbg("get iso = %d\n", isospeedrating);
	return isospeedrating;
}
Ejemplo n.º 5
0
static int sr200pc20_i2c_set_data_burst(struct i2c_client *client,
                                         regs_short_t reg_buffer[],
					                 int num_of_regs)
{
	unsigned short subaddr, data_value;
	int i, err = 0;

	for(i = 0; i < num_of_regs; i++) {
		subaddr = reg_buffer[i].subaddr;
		data_value = reg_buffer[i].value;

		switch(subaddr) {
		case DELAY_SEQ:
			cam_err("delay = %d\n",data_value*10);
			msleep(data_value * 10);
			break;
		default:
			err = sr200pc20_i2c_write_byte(client, subaddr, data_value);
			if(err < 0) {
				cam_err("i2c write fail\n");
				return -EIO;
			}
			break;
		}
	}

	return 0;
}
Ejemplo n.º 6
0
static int sr200pc20_get_expousretime(struct v4l2_subdev *sd,
					u32 *exp_time)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	u16 read_value = 0;
	u32 cintr = 0;

	sr200pc20_i2c_write_byte(client, 0x03, 0x20);
	sr200pc20_i2c_read_byte(client, 0x80, &read_value);
	cintr = read_value << 19;
	sr200pc20_i2c_read_byte(client, 0x81, &read_value);
	cintr |= read_value << 11;
	sr200pc20_i2c_read_byte(client, 0x82, &read_value);
	cintr |= read_value << 3;

	*exp_time =  cintr / 24; /* us */

	return 0;
}
Ejemplo n.º 7
0
static int sr200pc20_init_regs(struct v4l2_subdev *sd)
{
	struct sr200pc20_state *state = to_state(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	u16 read_value = 0;
	int err = -ENODEV;

	err = sr200pc20_i2c_write_byte(client, 0x03, 0x00);
	if (unlikely(err < 0))
		return -ENODEV;

	sr200pc20_i2c_read_byte(client, 0x04, &read_value);
	if (likely(read_value == SR200PC20_CHIP_ID))
		cam_info("Sensor ChipID: 0x%02X\n", SR200PC20_CHIP_ID);
	else
		cam_info("Sensor ChipID: 0x%02X, unknown chipID\n", read_value);

	state->regs = &reg_datas;

	return 0;
}
Ejemplo n.º 8
0
static int sr200pc20_get_shutterspeed(struct v4l2_subdev *sd)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	unsigned short read_value;
	int cintr;
	int ShutterSpeed = 0;

	sr200pc20_i2c_write_byte(client, 0x03, 0x20);
	sr200pc20_i2c_read_byte(client, 0x80, &read_value);
	cintr = (int)read_value << 19;
	sr200pc20_i2c_read_byte(client, 0x81, &read_value);
	cintr += (int)read_value << 11;
	sr200pc20_i2c_read_byte(client, 0x82, &read_value);
	cintr += (int)read_value << 3;

	cintr = cintr/24;
	ShutterSpeed =  1000000/cintr;

	cam_dbg("get shutterspeed = %d\n", ShutterSpeed);
	return ShutterSpeed;
}
Ejemplo n.º 9
0
static int sr200pc20_write_regs_from_sd(struct v4l2_subdev *sd, u8 s_name[])
{

	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct test *tempData = NULL;

	int ret = -EAGAIN;
	regs_short_t temp;
	u32 delay = 0;
	u8 data[11];
	s32 searched = 0, pair_cnt = 0, brace_cnt = 0;
	size_t size = strlen(s_name);
	s32 i;

	cam_trace("E size = %d, string = %s\n", size, s_name);
	tempData = &testBuf[0];
	while (!searched) {
		searched = 1;
		for (i = 0; i < size; i++) {
			if (tempData->data != s_name[i]) {
				searched = 0;
				break;
			}
			tempData = tempData->nextBuf;
		}
		tempData = tempData->nextBuf;
	}
	/* structure is get..*/

	while (1) {
		if (tempData->data == '{') {
			dbg_setfile("%s: found big_brace start\n", __func__);
			tempData = tempData->nextBuf;
			break;
		} else
			tempData = tempData->nextBuf;
	}

	while (1) {
		while (1) {
			if (tempData->data == '{') {
				/* dbg_setfile("%s: found small_brace start\n", __func__); */
				tempData = tempData->nextBuf;
				break;
			} else if (tempData->data == '}') {
				dbg_setfile("%s: found big_brace end\n", __func__);
				return 0;
			} else
				tempData = tempData->nextBuf;
		}
		
		searched = 0;
		pair_cnt = 0;
		while (1) {
			if (tempData->data == 'x') {
				/* get 10 strings.*/
				data[0] = '0';
				for (i = 1; i < 4; i++) {
					data[i] = tempData->data;
					tempData = tempData->nextBuf;
				}
				data[i] = '\0';
				/* dbg_setfile("read HEX: %s\n", data); */
				if (pair_cnt == 0) {
					temp.subaddr = simple_strtoul(data, NULL, 16);
					pair_cnt++;
				} else if (pair_cnt == 1) {
					temp.value = simple_strtoul(data, NULL, 16);
					pair_cnt++;
				}
			} else if (tempData->data == '}') {
				/* dbg_setfile("%s: found small_brace end\n", __func__); */
				tempData = tempData->nextBuf;
				/* searched = 1; */
				break;
			} else
				tempData = tempData->nextBuf;

			if (tempData->nextBuf == NULL)
				return -1;
		}

		if (searched)
			break;

		if ((temp.subaddr & 0xFF) == 0xFF) {
			delay = (temp.value & 0xFF) * 10;
			debug_msleep(sd, delay);
			continue;
		}

		/* cam_err("Write: 0x%02X, 0x%02X\n",
				(u8)(temp.subaddr), (u8)(temp.value)); */
		ret = sr200pc20_i2c_write_byte(client, temp.subaddr, temp.value);

		/* In error circumstances */
		/* Give second shot */
		if (unlikely(ret)) {
			dev_info(&client->dev,
					"sr200pc20 i2c retry one more time\n");
			ret = sr200pc20_i2c_write_byte(client, temp.subaddr, temp.value);

			/* Give it one more shot */
			if (unlikely(ret)) {
				dev_info(&client->dev,
						"sr200pc20 i2c retry twice\n");
				ret = sr200pc20_i2c_write_byte(client, temp.subaddr, temp.value);
			}
		}
	}

	return ret;
}