Lines Matching refs:state
203 int (*init)(struct adv7180_state *state);
231 static int adv7180_select_page(struct adv7180_state *state, unsigned int page)
233 if (state->register_page != page) {
234 i2c_smbus_write_byte_data(state->client, ADV7180_REG_CTRL,
236 state->register_page = page;
242 static int adv7180_write(struct adv7180_state *state, unsigned int reg,
245 lockdep_assert_held(&state->mutex);
246 adv7180_select_page(state, reg >> 8);
247 return i2c_smbus_write_byte_data(state->client, reg & 0xff, value);
250 static int adv7180_read(struct adv7180_state *state, unsigned int reg)
252 lockdep_assert_held(&state->mutex);
253 adv7180_select_page(state, reg >> 8);
254 return i2c_smbus_read_byte_data(state->client, reg & 0xff);
257 static int adv7180_csi_write(struct adv7180_state *state, unsigned int reg,
260 return i2c_smbus_write_byte_data(state->csi_client, reg, value);
263 static int adv7180_set_video_standard(struct adv7180_state *state,
266 return state->chip_info->set_std(state, std);
269 static int adv7180_vpp_write(struct adv7180_state *state, unsigned int reg,
272 return i2c_smbus_write_byte_data(state->vpp_client, reg, value);
334 static int __adv7180_status(struct adv7180_state *state, u32 *status,
337 int status1 = adv7180_read(state, ADV7180_REG_STATUS1);
357 struct adv7180_state *state = to_state(sd);
358 int err = mutex_lock_interruptible(&state->mutex);
362 if (state->streaming) {
367 err = adv7180_set_video_standard(state,
373 __adv7180_status(state, NULL, std);
375 err = v4l2_std_to_adv7180(state->curr_norm);
379 err = adv7180_set_video_standard(state, err);
382 mutex_unlock(&state->mutex);
389 struct adv7180_state *state = to_state(sd);
390 int ret = mutex_lock_interruptible(&state->mutex);
395 if (input > 31 || !(BIT(input) & state->chip_info->valid_input_mask)) {
400 ret = state->chip_info->select_input(state, input);
403 state->input = input;
405 mutex_unlock(&state->mutex);
411 struct adv7180_state *state = to_state(sd);
412 int ret = mutex_lock_interruptible(&state->mutex);
416 ret = __adv7180_status(state, status, NULL);
417 mutex_unlock(&state->mutex);
421 static int adv7180_program_std(struct adv7180_state *state)
425 ret = v4l2_std_to_adv7180(state->curr_norm);
429 ret = adv7180_set_video_standard(state, ret);
437 struct adv7180_state *state = to_state(sd);
438 int ret = mutex_lock_interruptible(&state->mutex);
448 state->curr_norm = std;
450 ret = adv7180_program_std(state);
452 mutex_unlock(&state->mutex);
458 struct adv7180_state *state = to_state(sd);
460 *norm = state->curr_norm;
468 struct adv7180_state *state = to_state(sd);
470 if (state->curr_norm & V4L2_STD_525_60) {
481 static void adv7180_set_power_pin(struct adv7180_state *state, bool on)
483 if (!state->pwdn_gpio)
487 gpiod_set_value_cansleep(state->pwdn_gpio, 0);
490 gpiod_set_value_cansleep(state->pwdn_gpio, 1);
494 static void adv7180_set_reset_pin(struct adv7180_state *state, bool on)
496 if (!state->rst_gpio)
500 gpiod_set_value_cansleep(state->rst_gpio, 1);
502 gpiod_set_value_cansleep(state->rst_gpio, 0);
507 static int adv7180_set_power(struct adv7180_state *state, bool on)
517 ret = adv7180_write(state, ADV7180_REG_PWR_MAN, val);
521 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
523 adv7180_csi_write(state, 0xDE, 0x02);
524 adv7180_csi_write(state, 0xD2, 0xF7);
525 adv7180_csi_write(state, 0xD8, 0x65);
526 adv7180_csi_write(state, 0xE0, 0x09);
527 adv7180_csi_write(state, 0x2C, 0x00);
528 if (state->field == V4L2_FIELD_NONE)
529 adv7180_csi_write(state, 0x1D, 0x80);
530 adv7180_csi_write(state, 0x00, 0x00);
532 adv7180_csi_write(state, 0x00, 0x80);
541 struct adv7180_state *state = to_state(sd);
544 ret = mutex_lock_interruptible(&state->mutex);
548 ret = adv7180_set_power(state, on);
550 state->powered = on;
552 mutex_unlock(&state->mutex);
564 static int adv7180_test_pattern(struct adv7180_state *state, int value)
574 adv7180_write(state, ADV7180_REG_ANALOG_CLAMP_CTL, reg);
577 reg = adv7180_read(state, ADV7180_REG_DEF_VALUE_Y);
579 adv7180_write(state, ADV7180_REG_DEF_VALUE_Y, reg);
583 reg = adv7180_read(state, ADV7180_REG_DEF_VALUE_Y);
585 adv7180_write(state, ADV7180_REG_DEF_VALUE_Y, reg);
593 struct adv7180_state *state = to_state(sd);
594 int ret = mutex_lock_interruptible(&state->mutex);
602 ret = adv7180_write(state, ADV7180_REG_BRI, val);
606 ret = adv7180_write(state, ADV7180_REG_HUE, -val);
609 ret = adv7180_write(state, ADV7180_REG_CON, val);
616 ret = adv7180_write(state, ADV7180_REG_SD_SAT_CB, val);
619 ret = adv7180_write(state, ADV7180_REG_SD_SAT_CR, val);
624 adv7180_write(state, 0x80d9, 0x44);
625 adv7180_write(state, ADV7180_REG_FLCONTROL,
629 adv7180_write(state, 0x80d9, 0xc4);
630 adv7180_write(state, ADV7180_REG_FLCONTROL, 0x00);
634 ret = adv7180_test_pattern(state, val);
640 mutex_unlock(&state->mutex);
658 static int adv7180_init_controls(struct adv7180_state *state)
660 v4l2_ctrl_handler_init(&state->ctrl_hdl, 4);
662 v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
665 v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
668 v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
671 v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
674 v4l2_ctrl_new_custom(&state->ctrl_hdl, &adv7180_ctrl_fast_switch, NULL);
676 v4l2_ctrl_new_std_menu_items(&state->ctrl_hdl, &adv7180_ctrl_ops,
682 state->sd.ctrl_handler = &state->ctrl_hdl;
683 if (state->ctrl_hdl.error) {
684 int err = state->ctrl_hdl.error;
686 v4l2_ctrl_handler_free(&state->ctrl_hdl);
689 v4l2_ctrl_handler_setup(&state->ctrl_hdl);
693 static void adv7180_exit_controls(struct adv7180_state *state)
695 v4l2_ctrl_handler_free(&state->ctrl_hdl);
713 struct adv7180_state *state = to_state(sd);
718 fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576;
720 if (state->field == V4L2_FIELD_ALTERNATE)
726 static int adv7180_set_field_mode(struct adv7180_state *state)
728 if (!(state->chip_info->flags & ADV7180_FLAG_I2P))
731 if (state->field == V4L2_FIELD_NONE) {
732 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
733 adv7180_csi_write(state, 0x01, 0x20);
734 adv7180_csi_write(state, 0x02, 0x28);
735 adv7180_csi_write(state, 0x03, 0x38);
736 adv7180_csi_write(state, 0x04, 0x30);
737 adv7180_csi_write(state, 0x05, 0x30);
738 adv7180_csi_write(state, 0x06, 0x80);
739 adv7180_csi_write(state, 0x07, 0x70);
740 adv7180_csi_write(state, 0x08, 0x50);
742 adv7180_vpp_write(state, 0xa3, 0x00);
743 adv7180_vpp_write(state, 0x5b, 0x00);
744 adv7180_vpp_write(state, 0x55, 0x80);
746 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
747 adv7180_csi_write(state, 0x01, 0x18);
748 adv7180_csi_write(state, 0x02, 0x18);
749 adv7180_csi_write(state, 0x03, 0x30);
750 adv7180_csi_write(state, 0x04, 0x20);
751 adv7180_csi_write(state, 0x05, 0x28);
752 adv7180_csi_write(state, 0x06, 0x40);
753 adv7180_csi_write(state, 0x07, 0x58);
754 adv7180_csi_write(state, 0x08, 0x30);
756 adv7180_vpp_write(state, 0xa3, 0x70);
757 adv7180_vpp_write(state, 0x5b, 0x80);
758 adv7180_vpp_write(state, 0x55, 0x00);
768 struct adv7180_state *state = to_state(sd);
774 format->format.field = state->field;
784 struct adv7180_state *state = to_state(sd);
790 if (state->chip_info->flags & ADV7180_FLAG_I2P)
801 if (state->field != format->format.field) {
802 state->field = format->format.field;
803 adv7180_set_power(state, false);
804 adv7180_set_field_mode(state);
805 adv7180_set_power(state, true);
830 struct adv7180_state *state = to_state(sd);
832 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
859 struct adv7180_state *state = to_state(sd);
861 if (state->curr_norm & V4L2_STD_525_60) {
880 struct adv7180_state *state = to_state(sd);
885 state->streaming = enable;
890 ret = mutex_lock_interruptible(&state->mutex);
893 state->streaming = enable;
894 mutex_unlock(&state->mutex);
951 struct adv7180_state *state = devid;
954 mutex_lock(&state->mutex);
955 isr3 = adv7180_read(state, ADV7180_REG_ISR3);
957 adv7180_write(state, ADV7180_REG_ICR3, isr3);
965 v4l2_subdev_notify_event(&state->sd, &src_ch);
967 mutex_unlock(&state->mutex);
972 static int adv7180_init(struct adv7180_state *state)
977 ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
983 return adv7180_write(state, ADV7180_REG_NTSC_V_BIT_END,
987 static int adv7180_set_std(struct adv7180_state *state, unsigned int std)
989 return adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
990 (std << 4) | state->input);
993 static int adv7180_select_input(struct adv7180_state *state, unsigned int input)
997 ret = adv7180_read(state, ADV7180_REG_INPUT_CONTROL);
1003 return adv7180_write(state, ADV7180_REG_INPUT_CONTROL, ret);
1006 static int adv7182_init(struct adv7180_state *state)
1008 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
1009 adv7180_write(state, ADV7180_REG_CSI_SLAVE_ADDR,
1012 if (state->chip_info->flags & ADV7180_FLAG_I2P)
1013 adv7180_write(state, ADV7180_REG_VPP_SLAVE_ADDR,
1016 if (state->chip_info->flags & ADV7180_FLAG_V2) {
1018 adv7180_write(state, 0x0080, 0x51);
1019 adv7180_write(state, 0x0081, 0x51);
1020 adv7180_write(state, 0x0082, 0x68);
1024 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
1025 adv7180_write(state, ADV7180_REG_OUTPUT_CONTROL, 0x4e);
1026 adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL, 0x57);
1027 adv7180_write(state, ADV7180_REG_CTRL_2, 0xc0);
1029 if (state->chip_info->flags & ADV7180_FLAG_V2) {
1030 if (state->force_bt656_4) {
1032 adv7180_write(state,
1036 adv7180_write(state,
1040 adv7180_write(state,
1044 adv7180_write(state,
1050 adv7180_write(state,
1053 adv7180_write(state, ADV7180_REG_OUTPUT_CONTROL, 0x0c);
1054 adv7180_write(state, ADV7180_REG_CTRL_2, 0x40);
1057 adv7180_write(state, 0x0013, 0x00);
1062 static int adv7182_set_std(struct adv7180_state *state, unsigned int std)
1065 return adv7180_write(state, ADV7182_REG_INPUT_VIDSEL,
1121 static int adv7182_select_input(struct adv7180_state *state, unsigned int input)
1128 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, input);
1133 adv7180_write(state, ADV7180_REG_RST_CLAMP, 0x00);
1134 adv7180_write(state, ADV7180_REG_RST_CLAMP, 0xff);
1142 adv7180_write(state, ADV7180_REG_SHAP_FILTER_CTL_1, 0x41);
1145 adv7180_write(state, ADV7180_REG_SHAP_FILTER_CTL_1, 0x01);
1149 if (state->chip_info->flags & ADV7180_FLAG_V2)
1155 adv7180_write(state, ADV7180_REG_CVBS_TRIM + i, lbias[i]);
1159 adv7180_write(state, ADV7180_REG_RES_CIR, 0xa8);
1160 adv7180_write(state, ADV7180_REG_CLAMP_ADJ, 0x90);
1161 adv7180_write(state, ADV7180_REG_DIFF_MODE, 0xb0);
1162 adv7180_write(state, ADV7180_REG_AGC_ADJ1, 0x08);
1163 adv7180_write(state, ADV7180_REG_AGC_ADJ2, 0xa0);
1165 adv7180_write(state, ADV7180_REG_RES_CIR, 0xf0);
1166 adv7180_write(state, ADV7180_REG_CLAMP_ADJ, 0xd0);
1167 adv7180_write(state, ADV7180_REG_DIFF_MODE, 0x10);
1168 adv7180_write(state, ADV7180_REG_AGC_ADJ1, 0x9c);
1169 adv7180_write(state, ADV7180_REG_AGC_ADJ2, 0x00);
1340 static int init_device(struct adv7180_state *state)
1344 mutex_lock(&state->mutex);
1346 adv7180_set_power_pin(state, true);
1347 adv7180_set_reset_pin(state, false);
1349 adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
1352 ret = state->chip_info->init(state);
1356 ret = adv7180_program_std(state);
1360 adv7180_set_field_mode(state);
1363 if (state->irq > 0) {
1365 ret = adv7180_write(state, ADV7180_REG_ICONF1,
1371 ret = adv7180_write(state, ADV7180_REG_IMR1, 0);
1375 ret = adv7180_write(state, ADV7180_REG_IMR2, 0);
1380 ret = adv7180_write(state, ADV7180_REG_IMR3,
1385 ret = adv7180_write(state, ADV7180_REG_IMR4, 0);
1391 mutex_unlock(&state->mutex);
1400 struct adv7180_state *state;
1408 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
1409 if (state == NULL)
1412 state->client = client;
1413 state->field = V4L2_FIELD_ALTERNATE;
1414 state->chip_info = (struct adv7180_chip_info *)id->driver_data;
1416 state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
1418 if (IS_ERR(state->pwdn_gpio)) {
1419 ret = PTR_ERR(state->pwdn_gpio);
1424 state->rst_gpio = devm_gpiod_get_optional(&client->dev, "reset",
1426 if (IS_ERR(state->rst_gpio)) {
1427 ret = PTR_ERR(state->rst_gpio);
1433 state->force_bt656_4 = true;
1435 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
1436 state->csi_client = i2c_new_dummy_device(client->adapter,
1438 if (IS_ERR(state->csi_client))
1439 return PTR_ERR(state->csi_client);
1442 if (state->chip_info->flags & ADV7180_FLAG_I2P) {
1443 state->vpp_client = i2c_new_dummy_device(client->adapter,
1445 if (IS_ERR(state->vpp_client)) {
1446 ret = PTR_ERR(state->vpp_client);
1451 state->irq = client->irq;
1452 mutex_init(&state->mutex);
1453 state->curr_norm = V4L2_STD_NTSC;
1454 if (state->chip_info->flags & ADV7180_FLAG_RESET_POWERED)
1455 state->powered = true;
1457 state->powered = false;
1458 state->input = 0;
1459 sd = &state->sd;
1463 ret = adv7180_init_controls(state);
1467 state->pad.flags = MEDIA_PAD_FL_SOURCE;
1469 ret = media_entity_pads_init(&sd->entity, 1, &state->pad);
1473 ret = init_device(state);
1477 if (state->irq) {
1480 KBUILD_MODNAME, state);
1489 mutex_lock(&state->mutex);
1490 ret = adv7180_read(state, ADV7180_REG_IDENT);
1491 mutex_unlock(&state->mutex);
1503 if (state->irq > 0)
1504 free_irq(client->irq, state);
1508 adv7180_exit_controls(state);
1510 i2c_unregister_device(state->vpp_client);
1512 i2c_unregister_device(state->csi_client);
1513 mutex_destroy(&state->mutex);
1520 struct adv7180_state *state = to_state(sd);
1524 if (state->irq > 0)
1525 free_irq(client->irq, state);
1528 adv7180_exit_controls(state);
1530 i2c_unregister_device(state->vpp_client);
1531 i2c_unregister_device(state->csi_client);
1533 adv7180_set_reset_pin(state, true);
1534 adv7180_set_power_pin(state, false);
1536 mutex_destroy(&state->mutex);
1559 struct adv7180_state *state = to_state(sd);
1561 return adv7180_set_power(state, false);
1567 struct adv7180_state *state = to_state(sd);
1570 ret = init_device(state);
1574 ret = adv7180_set_power(state, state->powered);