Lines Matching refs:state
422 static u16 s5k5baf_i2c_read(struct s5k5baf *state, u16 addr) in s5k5baf_i2c_read() argument
424 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); in s5k5baf_i2c_read()
435 if (state->error) in s5k5baf_i2c_read()
446 state->error = ret; in s5k5baf_i2c_read()
451 static void s5k5baf_i2c_write(struct s5k5baf *state, u16 addr, u16 val) in s5k5baf_i2c_write() argument
454 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); in s5k5baf_i2c_write()
457 if (state->error) in s5k5baf_i2c_write()
465 state->error = ret; in s5k5baf_i2c_write()
469 static u16 s5k5baf_read(struct s5k5baf *state, u16 addr) in s5k5baf_read() argument
471 s5k5baf_i2c_write(state, REG_CMDRD_ADDR, addr); in s5k5baf_read()
472 return s5k5baf_i2c_read(state, REG_CMD_BUF); in s5k5baf_read()
475 static void s5k5baf_write(struct s5k5baf *state, u16 addr, u16 val) in s5k5baf_write() argument
477 s5k5baf_i2c_write(state, REG_CMDWR_ADDR, addr); in s5k5baf_write()
478 s5k5baf_i2c_write(state, REG_CMD_BUF, val); in s5k5baf_write()
481 static void s5k5baf_write_arr_seq(struct s5k5baf *state, u16 addr, in s5k5baf_write_arr_seq() argument
484 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); in s5k5baf_write_arr_seq()
487 s5k5baf_i2c_write(state, REG_CMDWR_ADDR, addr); in s5k5baf_write_arr_seq()
488 if (state->error) in s5k5baf_write_arr_seq()
507 state->error = ret; in s5k5baf_write_arr_seq()
515 #define s5k5baf_write_seq(state, addr, seq...) \ argument
516 s5k5baf_write_arr_seq(state, addr, sizeof((char[]){ seq }), \
530 static void s5k5baf_write_nseq(struct s5k5baf *state, const u16 *nseq) in s5k5baf_write_nseq() argument
538 s5k5baf_write_arr_seq(state, addr, count, nseq); in s5k5baf_write_nseq()
543 static void s5k5baf_synchronize(struct s5k5baf *state, int timeout, u16 addr) in s5k5baf_synchronize() argument
548 s5k5baf_write(state, addr, 1); in s5k5baf_synchronize()
550 reg = s5k5baf_read(state, addr); in s5k5baf_synchronize()
551 if (state->error || !reg) in s5k5baf_synchronize()
556 v4l2_err(&state->sd, "timeout on register synchronize (%#x)\n", addr); in s5k5baf_synchronize()
557 state->error = -ETIMEDOUT; in s5k5baf_synchronize()
560 static u16 *s5k5baf_fw_get_seq(struct s5k5baf *state, u16 seq_id) in s5k5baf_fw_get_seq() argument
562 struct s5k5baf_fw *fw = state->fw; in s5k5baf_fw_get_seq()
579 static void s5k5baf_hw_patch(struct s5k5baf *state) in s5k5baf_hw_patch() argument
581 u16 *seq = s5k5baf_fw_get_seq(state, S5K5BAF_FW_ID_PATCH); in s5k5baf_hw_patch()
584 s5k5baf_write_nseq(state, seq); in s5k5baf_hw_patch()
587 static void s5k5baf_hw_set_clocks(struct s5k5baf *state) in s5k5baf_hw_set_clocks() argument
589 unsigned long mclk = state->mclk_frequency / 1000; in s5k5baf_hw_set_clocks()
600 s5k5baf_write_seq(state, REG_I_INCLK_FREQ_L, mclk & 0xffff, mclk >> 16); in s5k5baf_hw_set_clocks()
601 s5k5baf_write_nseq(state, nseq_clk_cfg); in s5k5baf_hw_set_clocks()
603 s5k5baf_synchronize(state, 250, REG_I_INIT_PARAMS_UPDATED); in s5k5baf_hw_set_clocks()
604 status = s5k5baf_read(state, REG_I_ERROR_INFO); in s5k5baf_hw_set_clocks()
605 if (!state->error && status) { in s5k5baf_hw_set_clocks()
606 v4l2_err(&state->sd, "error configuring PLL (%d)\n", status); in s5k5baf_hw_set_clocks()
607 state->error = -EINVAL; in s5k5baf_hw_set_clocks()
612 static void s5k5baf_hw_set_ccm(struct s5k5baf *state) in s5k5baf_hw_set_ccm() argument
614 u16 *seq = s5k5baf_fw_get_seq(state, S5K5BAF_FW_ID_CCM); in s5k5baf_hw_set_ccm()
617 s5k5baf_write_nseq(state, seq); in s5k5baf_hw_set_ccm()
621 static void s5k5baf_hw_set_cis(struct s5k5baf *state) in s5k5baf_hw_set_cis() argument
623 u16 *seq = s5k5baf_fw_get_seq(state, S5K5BAF_FW_ID_CIS); in s5k5baf_hw_set_cis()
628 s5k5baf_i2c_write(state, REG_CMDWR_PAGE, PAGE_IF_HW); in s5k5baf_hw_set_cis()
629 s5k5baf_write_nseq(state, seq); in s5k5baf_hw_set_cis()
630 s5k5baf_i2c_write(state, REG_CMDWR_PAGE, PAGE_IF_SW); in s5k5baf_hw_set_cis()
633 static void s5k5baf_hw_sync_cfg(struct s5k5baf *state) in s5k5baf_hw_sync_cfg() argument
635 s5k5baf_write(state, REG_G_PREV_CFG_CHG, 1); in s5k5baf_hw_sync_cfg()
636 if (state->apply_crop) { in s5k5baf_hw_sync_cfg()
637 s5k5baf_write(state, REG_G_INPUTS_CHANGE_REQ, 1); in s5k5baf_hw_sync_cfg()
638 s5k5baf_write(state, REG_G_PREV_CFG_BYPASS_CHANGED, 1); in s5k5baf_hw_sync_cfg()
640 s5k5baf_synchronize(state, 500, REG_G_NEW_CFG_SYNC); in s5k5baf_hw_sync_cfg()
643 static void s5k5baf_hw_set_mirror(struct s5k5baf *state) in s5k5baf_hw_set_mirror() argument
645 u16 flip = state->ctrls.vflip->val | (state->ctrls.vflip->val << 1); in s5k5baf_hw_set_mirror()
647 s5k5baf_write(state, REG_P_PREV_MIRROR(0), flip); in s5k5baf_hw_set_mirror()
648 if (state->streaming) in s5k5baf_hw_set_mirror()
649 s5k5baf_hw_sync_cfg(state); in s5k5baf_hw_set_mirror()
652 static void s5k5baf_hw_set_alg(struct s5k5baf *state, u16 alg, bool enable) in s5k5baf_hw_set_alg() argument
656 if (!state->valid_auto_alg) in s5k5baf_hw_set_alg()
657 cur_alg = s5k5baf_read(state, REG_DBG_AUTOALG_EN); in s5k5baf_hw_set_alg()
659 cur_alg = state->auto_alg; in s5k5baf_hw_set_alg()
664 s5k5baf_write(state, REG_DBG_AUTOALG_EN, new_alg); in s5k5baf_hw_set_alg()
666 if (state->error) in s5k5baf_hw_set_alg()
669 state->valid_auto_alg = 1; in s5k5baf_hw_set_alg()
670 state->auto_alg = new_alg; in s5k5baf_hw_set_alg()
674 static void s5k5baf_hw_set_awb(struct s5k5baf *state, int awb) in s5k5baf_hw_set_awb() argument
676 struct s5k5baf_ctrls *ctrls = &state->ctrls; in s5k5baf_hw_set_awb()
679 s5k5baf_write_seq(state, REG_SF_RGAIN, in s5k5baf_hw_set_awb()
685 s5k5baf_hw_set_alg(state, AALG_WB_EN, awb); in s5k5baf_hw_set_awb()
689 static void s5k5baf_hw_set_user_exposure(struct s5k5baf *state, int exposure) in s5k5baf_hw_set_user_exposure() argument
693 s5k5baf_write_seq(state, REG_SF_USR_EXPOSURE_L, in s5k5baf_hw_set_user_exposure()
697 static void s5k5baf_hw_set_user_gain(struct s5k5baf *state, int gain) in s5k5baf_hw_set_user_gain() argument
699 s5k5baf_write_seq(state, REG_SF_USR_TOT_GAIN, gain, 1); in s5k5baf_hw_set_user_gain()
703 static void s5k5baf_hw_set_auto_exposure(struct s5k5baf *state, int value) in s5k5baf_hw_set_auto_exposure() argument
706 s5k5baf_hw_set_alg(state, AALG_AE_EN | AALG_DIVLEI_EN, true); in s5k5baf_hw_set_auto_exposure()
708 unsigned int exp_time = state->ctrls.exposure->val; in s5k5baf_hw_set_auto_exposure()
710 s5k5baf_hw_set_user_exposure(state, exp_time); in s5k5baf_hw_set_auto_exposure()
711 s5k5baf_hw_set_user_gain(state, state->ctrls.gain->val); in s5k5baf_hw_set_auto_exposure()
712 s5k5baf_hw_set_alg(state, AALG_AE_EN | AALG_DIVLEI_EN, false); in s5k5baf_hw_set_auto_exposure()
716 static void s5k5baf_hw_set_anti_flicker(struct s5k5baf *state, int v) in s5k5baf_hw_set_anti_flicker() argument
719 s5k5baf_hw_set_alg(state, AALG_FLICKER_EN, true); in s5k5baf_hw_set_anti_flicker()
723 s5k5baf_write_seq(state, REG_SF_FLICKER_QUANT, v, 1); in s5k5baf_hw_set_anti_flicker()
724 s5k5baf_hw_set_alg(state, AALG_FLICKER_EN, false); in s5k5baf_hw_set_anti_flicker()
728 static void s5k5baf_hw_set_colorfx(struct s5k5baf *state, int val) in s5k5baf_hw_set_colorfx() argument
739 s5k5baf_write(state, REG_G_SPEC_EFFECTS, colorfx[val]); in s5k5baf_hw_set_colorfx()
757 static int s5k5baf_clear_error(struct s5k5baf *state) in s5k5baf_clear_error() argument
759 int ret = state->error; in s5k5baf_clear_error()
761 state->error = 0; in s5k5baf_clear_error()
765 static int s5k5baf_hw_set_video_bus(struct s5k5baf *state) in s5k5baf_hw_set_video_bus() argument
769 if (state->bus_type == V4L2_MBUS_CSI2) in s5k5baf_hw_set_video_bus()
774 s5k5baf_write_seq(state, REG_OIF_EN_MIPI_LANES, in s5k5baf_hw_set_video_bus()
775 state->nlanes, en_pkts, 1); in s5k5baf_hw_set_video_bus()
777 return s5k5baf_clear_error(state); in s5k5baf_hw_set_video_bus()
780 static u16 s5k5baf_get_cfg_error(struct s5k5baf *state) in s5k5baf_get_cfg_error() argument
782 u16 err = s5k5baf_read(state, REG_G_PREV_CFG_ERROR); in s5k5baf_get_cfg_error()
784 s5k5baf_write(state, REG_G_PREV_CFG_ERROR, 0); in s5k5baf_get_cfg_error()
788 static void s5k5baf_hw_set_fiv(struct s5k5baf *state, u16 fiv) in s5k5baf_hw_set_fiv() argument
790 s5k5baf_write(state, REG_P_MAX_FR_TIME(0), fiv); in s5k5baf_hw_set_fiv()
791 s5k5baf_hw_sync_cfg(state); in s5k5baf_hw_set_fiv()
794 static void s5k5baf_hw_find_min_fiv(struct s5k5baf *state) in s5k5baf_hw_find_min_fiv() argument
799 fiv = s5k5baf_read(state, REG_G_ACTUAL_P_FR_TIME); in s5k5baf_hw_find_min_fiv()
800 if (state->error) in s5k5baf_hw_find_min_fiv()
804 s5k5baf_hw_set_fiv(state, fiv); in s5k5baf_hw_find_min_fiv()
805 err = s5k5baf_get_cfg_error(state); in s5k5baf_hw_find_min_fiv()
806 if (state->error) in s5k5baf_hw_find_min_fiv()
813 state->fiv = fiv; in s5k5baf_hw_find_min_fiv()
814 v4l2_info(&state->sd, in s5k5baf_hw_find_min_fiv()
818 v4l2_err(&state->sd, in s5k5baf_hw_find_min_fiv()
820 state->error = -EINVAL; in s5k5baf_hw_find_min_fiv()
823 v4l2_err(&state->sd, "cannot find correct frame interval\n"); in s5k5baf_hw_find_min_fiv()
824 state->error = -ERANGE; in s5k5baf_hw_find_min_fiv()
827 static void s5k5baf_hw_validate_cfg(struct s5k5baf *state) in s5k5baf_hw_validate_cfg() argument
831 err = s5k5baf_get_cfg_error(state); in s5k5baf_hw_validate_cfg()
832 if (state->error) in s5k5baf_hw_validate_cfg()
837 state->apply_cfg = 1; in s5k5baf_hw_validate_cfg()
840 s5k5baf_hw_find_min_fiv(state); in s5k5baf_hw_validate_cfg()
841 if (!state->error) in s5k5baf_hw_validate_cfg()
842 state->apply_cfg = 1; in s5k5baf_hw_validate_cfg()
845 v4l2_err(&state->sd, in s5k5baf_hw_validate_cfg()
847 state->error = -EINVAL; in s5k5baf_hw_validate_cfg()
861 static int s5k5baf_hw_set_crop_rects(struct s5k5baf *state) in s5k5baf_hw_set_crop_rects() argument
867 p = &state->crop_sink; in s5k5baf_hw_set_crop_rects()
868 s5k5baf_write_seq(state, REG_G_PREVREQ_IN_WIDTH, p->width, p->height, in s5k5baf_hw_set_crop_rects()
871 s5k5baf_rescale(&r, &state->crop_source, &state->crop_sink, in s5k5baf_hw_set_crop_rects()
872 &state->compose); in s5k5baf_hw_set_crop_rects()
873 s5k5baf_write_seq(state, REG_G_PREVZOOM_IN_WIDTH, r.width, r.height, in s5k5baf_hw_set_crop_rects()
876 s5k5baf_synchronize(state, 500, REG_G_INPUTS_CHANGE_REQ); in s5k5baf_hw_set_crop_rects()
877 s5k5baf_synchronize(state, 500, REG_G_PREV_CFG_BYPASS_CHANGED); in s5k5baf_hw_set_crop_rects()
878 err = s5k5baf_get_cfg_error(state); in s5k5baf_hw_set_crop_rects()
879 ret = s5k5baf_clear_error(state); in s5k5baf_hw_set_crop_rects()
888 s5k5baf_hw_set_fiv(state, S5K5BAF_MAX_FR_TIME); in s5k5baf_hw_set_crop_rects()
889 err = s5k5baf_get_cfg_error(state); in s5k5baf_hw_set_crop_rects()
890 ret = s5k5baf_clear_error(state); in s5k5baf_hw_set_crop_rects()
894 v4l2_err(&state->sd, in s5k5baf_hw_set_crop_rects()
896 state->error = -EINVAL; in s5k5baf_hw_set_crop_rects()
898 s5k5baf_hw_set_fiv(state, state->req_fiv); in s5k5baf_hw_set_crop_rects()
899 s5k5baf_hw_validate_cfg(state); in s5k5baf_hw_set_crop_rects()
902 v4l2_err(&state->sd, "crop error: %d\n", err); in s5k5baf_hw_set_crop_rects()
906 if (!state->apply_cfg) in s5k5baf_hw_set_crop_rects()
909 p = &state->crop_source; in s5k5baf_hw_set_crop_rects()
910 s5k5baf_write_seq(state, REG_P_OUT_WIDTH(0), p->width, p->height); in s5k5baf_hw_set_crop_rects()
911 s5k5baf_hw_set_fiv(state, state->req_fiv); in s5k5baf_hw_set_crop_rects()
912 s5k5baf_hw_validate_cfg(state); in s5k5baf_hw_set_crop_rects()
914 return s5k5baf_clear_error(state); in s5k5baf_hw_set_crop_rects()
917 static void s5k5baf_hw_set_config(struct s5k5baf *state) in s5k5baf_hw_set_config() argument
919 u16 reg_fmt = s5k5baf_formats[state->pixfmt].reg_p_fmt; in s5k5baf_hw_set_config()
920 struct v4l2_rect *r = &state->crop_source; in s5k5baf_hw_set_config()
922 s5k5baf_write_seq(state, REG_P_OUT_WIDTH(0), in s5k5baf_hw_set_config()
927 state->req_fiv, S5K5BAF_MIN_FR_TIME); in s5k5baf_hw_set_config()
928 s5k5baf_hw_sync_cfg(state); in s5k5baf_hw_set_config()
929 s5k5baf_hw_validate_cfg(state); in s5k5baf_hw_set_config()
933 static void s5k5baf_hw_set_test_pattern(struct s5k5baf *state, int id) in s5k5baf_hw_set_test_pattern() argument
935 s5k5baf_i2c_write(state, REG_PATTERN_WIDTH, 800); in s5k5baf_hw_set_test_pattern()
936 s5k5baf_i2c_write(state, REG_PATTERN_HEIGHT, 511); in s5k5baf_hw_set_test_pattern()
937 s5k5baf_i2c_write(state, REG_PATTERN_PARAM, 0); in s5k5baf_hw_set_test_pattern()
938 s5k5baf_i2c_write(state, REG_PATTERN_SET, id); in s5k5baf_hw_set_test_pattern()
941 static void s5k5baf_gpio_assert(struct s5k5baf *state, int id) in s5k5baf_gpio_assert() argument
943 struct s5k5baf_gpio *gpio = &state->gpios[id]; in s5k5baf_gpio_assert()
948 static void s5k5baf_gpio_deassert(struct s5k5baf *state, int id) in s5k5baf_gpio_deassert() argument
950 struct s5k5baf_gpio *gpio = &state->gpios[id]; in s5k5baf_gpio_deassert()
955 static int s5k5baf_power_on(struct s5k5baf *state) in s5k5baf_power_on() argument
959 ret = regulator_bulk_enable(S5K5BAF_NUM_SUPPLIES, state->supplies); in s5k5baf_power_on()
963 ret = clk_set_rate(state->clock, state->mclk_frequency); in s5k5baf_power_on()
967 ret = clk_prepare_enable(state->clock); in s5k5baf_power_on()
971 v4l2_dbg(1, debug, &state->sd, "clock frequency: %ld\n", in s5k5baf_power_on()
972 clk_get_rate(state->clock)); in s5k5baf_power_on()
974 s5k5baf_gpio_deassert(state, STBY); in s5k5baf_power_on()
976 s5k5baf_gpio_deassert(state, RST); in s5k5baf_power_on()
980 regulator_bulk_disable(S5K5BAF_NUM_SUPPLIES, state->supplies); in s5k5baf_power_on()
982 v4l2_err(&state->sd, "%s() failed (%d)\n", __func__, ret); in s5k5baf_power_on()
986 static int s5k5baf_power_off(struct s5k5baf *state) in s5k5baf_power_off() argument
990 state->streaming = 0; in s5k5baf_power_off()
991 state->apply_cfg = 0; in s5k5baf_power_off()
992 state->apply_crop = 0; in s5k5baf_power_off()
994 s5k5baf_gpio_assert(state, RST); in s5k5baf_power_off()
995 s5k5baf_gpio_assert(state, STBY); in s5k5baf_power_off()
997 if (!IS_ERR(state->clock)) in s5k5baf_power_off()
998 clk_disable_unprepare(state->clock); in s5k5baf_power_off()
1001 state->supplies); in s5k5baf_power_off()
1003 v4l2_err(&state->sd, "failed to disable regulators\n"); in s5k5baf_power_off()
1008 static void s5k5baf_hw_init(struct s5k5baf *state) in s5k5baf_hw_init() argument
1010 s5k5baf_i2c_write(state, AHB_MSB_ADDR_PTR, PAGE_IF_HW); in s5k5baf_hw_init()
1011 s5k5baf_i2c_write(state, REG_CLEAR_HOST_INT, 0); in s5k5baf_hw_init()
1012 s5k5baf_i2c_write(state, REG_SW_LOAD_COMPLETE, 1); in s5k5baf_hw_init()
1013 s5k5baf_i2c_write(state, REG_CMDRD_PAGE, PAGE_IF_SW); in s5k5baf_hw_init()
1014 s5k5baf_i2c_write(state, REG_CMDWR_PAGE, PAGE_IF_SW); in s5k5baf_hw_init()
1021 static void s5k5baf_initialize_data(struct s5k5baf *state) in s5k5baf_initialize_data() argument
1023 state->pixfmt = 0; in s5k5baf_initialize_data()
1024 state->req_fiv = 10000 / 15; in s5k5baf_initialize_data()
1025 state->fiv = state->req_fiv; in s5k5baf_initialize_data()
1026 state->valid_auto_alg = 0; in s5k5baf_initialize_data()
1029 static int s5k5baf_load_setfile(struct s5k5baf *state) in s5k5baf_load_setfile() argument
1031 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); in s5k5baf_load_setfile()
1042 ret = s5k5baf_fw_parse(&c->dev, &state->fw, fw->size / 2, in s5k5baf_load_setfile()
1052 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_set_power() local
1055 mutex_lock(&state->lock); in s5k5baf_set_power()
1057 if (!on != state->power) in s5k5baf_set_power()
1061 if (state->fw == NULL) in s5k5baf_set_power()
1062 s5k5baf_load_setfile(state); in s5k5baf_set_power()
1064 s5k5baf_initialize_data(state); in s5k5baf_set_power()
1065 ret = s5k5baf_power_on(state); in s5k5baf_set_power()
1069 s5k5baf_hw_init(state); in s5k5baf_set_power()
1070 s5k5baf_hw_patch(state); in s5k5baf_set_power()
1071 s5k5baf_i2c_write(state, REG_SET_HOST_INT, 1); in s5k5baf_set_power()
1072 s5k5baf_hw_set_clocks(state); in s5k5baf_set_power()
1074 ret = s5k5baf_hw_set_video_bus(state); in s5k5baf_set_power()
1078 s5k5baf_hw_set_cis(state); in s5k5baf_set_power()
1079 s5k5baf_hw_set_ccm(state); in s5k5baf_set_power()
1081 ret = s5k5baf_clear_error(state); in s5k5baf_set_power()
1083 state->power++; in s5k5baf_set_power()
1085 s5k5baf_power_off(state); in s5k5baf_set_power()
1086 state->power--; in s5k5baf_set_power()
1090 mutex_unlock(&state->lock); in s5k5baf_set_power()
1093 ret = v4l2_ctrl_handler_setup(&state->ctrls.handler); in s5k5baf_set_power()
1098 static void s5k5baf_hw_set_stream(struct s5k5baf *state, int enable) in s5k5baf_hw_set_stream() argument
1100 s5k5baf_write_seq(state, REG_G_ENABLE_PREV, enable, 1); in s5k5baf_hw_set_stream()
1105 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_s_stream() local
1108 mutex_lock(&state->lock); in s5k5baf_s_stream()
1110 if (state->streaming == !!on) { in s5k5baf_s_stream()
1116 s5k5baf_hw_set_config(state); in s5k5baf_s_stream()
1117 ret = s5k5baf_hw_set_crop_rects(state); in s5k5baf_s_stream()
1120 s5k5baf_hw_set_stream(state, 1); in s5k5baf_s_stream()
1121 s5k5baf_i2c_write(state, 0xb0cc, 0x000b); in s5k5baf_s_stream()
1123 s5k5baf_hw_set_stream(state, 0); in s5k5baf_s_stream()
1125 ret = s5k5baf_clear_error(state); in s5k5baf_s_stream()
1127 state->streaming = !state->streaming; in s5k5baf_s_stream()
1130 mutex_unlock(&state->lock); in s5k5baf_s_stream()
1138 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_g_frame_interval() local
1140 mutex_lock(&state->lock); in s5k5baf_g_frame_interval()
1141 fi->interval.numerator = state->fiv; in s5k5baf_g_frame_interval()
1143 mutex_unlock(&state->lock); in s5k5baf_g_frame_interval()
1148 static void s5k5baf_set_frame_interval(struct s5k5baf *state, in s5k5baf_set_frame_interval() argument
1154 state->req_fiv = S5K5BAF_MAX_FR_TIME; in s5k5baf_set_frame_interval()
1156 state->req_fiv = clamp_t(u32, in s5k5baf_set_frame_interval()
1161 state->fiv = state->req_fiv; in s5k5baf_set_frame_interval()
1162 if (state->apply_cfg) { in s5k5baf_set_frame_interval()
1163 s5k5baf_hw_set_fiv(state, state->req_fiv); in s5k5baf_set_frame_interval()
1164 s5k5baf_hw_validate_cfg(state); in s5k5baf_set_frame_interval()
1166 *i = (struct v4l2_fract){ state->fiv, 10000 }; in s5k5baf_set_frame_interval()
1167 if (state->fiv == state->req_fiv) in s5k5baf_set_frame_interval()
1168 v4l2_info(&state->sd, "frame interval changed to %d00us\n", in s5k5baf_set_frame_interval()
1169 state->fiv); in s5k5baf_set_frame_interval()
1175 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_s_frame_interval() local
1177 mutex_lock(&state->lock); in s5k5baf_s_frame_interval()
1178 s5k5baf_set_frame_interval(state, fi); in s5k5baf_s_frame_interval()
1179 mutex_unlock(&state->lock); in s5k5baf_s_frame_interval()
1284 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_get_fmt() local
1300 mutex_lock(&state->lock); in s5k5baf_get_fmt()
1301 pixfmt = &s5k5baf_formats[state->pixfmt]; in s5k5baf_get_fmt()
1302 mf->width = state->crop_source.width; in s5k5baf_get_fmt()
1303 mf->height = state->crop_source.height; in s5k5baf_get_fmt()
1306 mutex_unlock(&state->lock); in s5k5baf_get_fmt()
1315 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_set_fmt() local
1331 mutex_lock(&state->lock); in s5k5baf_set_fmt()
1333 if (state->streaming) { in s5k5baf_set_fmt()
1334 mutex_unlock(&state->lock); in s5k5baf_set_fmt()
1338 state->pixfmt = s5k5baf_try_isp_format(mf); in s5k5baf_set_fmt()
1339 pixfmt = &s5k5baf_formats[state->pixfmt]; in s5k5baf_set_fmt()
1342 mf->width = state->crop_source.width; in s5k5baf_set_fmt()
1343 mf->height = state->crop_source.height; in s5k5baf_set_fmt()
1345 mutex_unlock(&state->lock); in s5k5baf_set_fmt()
1378 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_get_selection() local
1400 mutex_lock(&state->lock); in s5k5baf_get_selection()
1403 sel->r = state->crop_sink; in s5k5baf_get_selection()
1406 sel->r = state->compose; in s5k5baf_get_selection()
1409 sel->r = state->crop_source; in s5k5baf_get_selection()
1418 mutex_unlock(&state->lock); in s5k5baf_get_selection()
1469 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_set_selection() local
1496 &state->crop_sink, in s5k5baf_set_selection()
1497 &state->compose, in s5k5baf_set_selection()
1498 &state->crop_source in s5k5baf_set_selection()
1500 mutex_lock(&state->lock); in s5k5baf_set_selection()
1501 if (state->streaming) { in s5k5baf_set_selection()
1504 if (sel->r.width < state->crop_source.width) in s5k5baf_set_selection()
1505 sel->r.width = state->crop_source.width; in s5k5baf_set_selection()
1506 if (sel->r.height < state->crop_source.height) in s5k5baf_set_selection()
1507 sel->r.height = state->crop_source.height; in s5k5baf_set_selection()
1509 sel->r.width = state->crop_source.width; in s5k5baf_set_selection()
1510 sel->r.height = state->crop_source.height; in s5k5baf_set_selection()
1514 if (!s5k5baf_cmp_rect(&state->crop_sink, &s5k5baf_cis_rect) || in s5k5baf_set_selection()
1515 !s5k5baf_cmp_rect(&state->compose, &s5k5baf_cis_rect)) in s5k5baf_set_selection()
1516 state->apply_crop = 1; in s5k5baf_set_selection()
1517 if (state->streaming) in s5k5baf_set_selection()
1518 ret = s5k5baf_hw_set_crop_rects(state); in s5k5baf_set_selection()
1519 mutex_unlock(&state->lock); in s5k5baf_set_selection()
1554 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_s_ctrl() local
1559 mutex_lock(&state->lock); in s5k5baf_s_ctrl()
1561 if (state->power == 0) in s5k5baf_s_ctrl()
1566 s5k5baf_hw_set_awb(state, ctrl->val); in s5k5baf_s_ctrl()
1570 s5k5baf_write(state, REG_USER_BRIGHTNESS, ctrl->val); in s5k5baf_s_ctrl()
1574 s5k5baf_hw_set_colorfx(state, ctrl->val); in s5k5baf_s_ctrl()
1578 s5k5baf_write(state, REG_USER_CONTRAST, ctrl->val); in s5k5baf_s_ctrl()
1582 s5k5baf_hw_set_auto_exposure(state, ctrl->val); in s5k5baf_s_ctrl()
1586 s5k5baf_hw_set_mirror(state); in s5k5baf_s_ctrl()
1590 s5k5baf_hw_set_anti_flicker(state, ctrl->val); in s5k5baf_s_ctrl()
1594 s5k5baf_write(state, REG_USER_SATURATION, ctrl->val); in s5k5baf_s_ctrl()
1598 s5k5baf_write(state, REG_USER_SHARPBLUR, ctrl->val); in s5k5baf_s_ctrl()
1602 s5k5baf_write(state, REG_P_COLORTEMP(0), ctrl->val); in s5k5baf_s_ctrl()
1603 if (state->apply_cfg) in s5k5baf_s_ctrl()
1604 s5k5baf_hw_sync_cfg(state); in s5k5baf_s_ctrl()
1608 s5k5baf_hw_set_test_pattern(state, ctrl->val); in s5k5baf_s_ctrl()
1612 ret = s5k5baf_clear_error(state); in s5k5baf_s_ctrl()
1613 mutex_unlock(&state->lock); in s5k5baf_s_ctrl()
1631 static int s5k5baf_initialize_ctrls(struct s5k5baf *state) in s5k5baf_initialize_ctrls() argument
1634 struct s5k5baf_ctrls *ctrls = &state->ctrls; in s5k5baf_initialize_ctrls()
1640 v4l2_err(&state->sd, "cannot init ctrl handler (%d)\n", ret); in s5k5baf_initialize_ctrls()
1688 v4l2_err(&state->sd, "error creating controls (%d)\n", in s5k5baf_initialize_ctrls()
1695 state->sd.ctrl_handler = hdl; in s5k5baf_initialize_ctrls()
1726 static int s5k5baf_check_fw_revision(struct s5k5baf *state) in s5k5baf_check_fw_revision() argument
1731 api_ver = s5k5baf_read(state, REG_FW_APIVER); in s5k5baf_check_fw_revision()
1732 fw_rev = s5k5baf_read(state, REG_FW_REVISION) & 0xff; in s5k5baf_check_fw_revision()
1733 s_id = s5k5baf_read(state, REG_FW_SENSOR_ID); in s5k5baf_check_fw_revision()
1734 ret = s5k5baf_clear_error(state); in s5k5baf_check_fw_revision()
1738 v4l2_info(&state->sd, "FW API=%#x, revision=%#x sensor_id=%#x\n", in s5k5baf_check_fw_revision()
1742 v4l2_err(&state->sd, "FW API version not supported\n"); in s5k5baf_check_fw_revision()
1751 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_registered() local
1754 ret = v4l2_device_register_subdev(sd->v4l2_dev, &state->cis_sd); in s5k5baf_registered()
1757 state->cis_sd.name); in s5k5baf_registered()
1759 ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS, in s5k5baf_registered()
1760 &state->sd.entity, PAD_CIS, in s5k5baf_registered()
1768 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_unregistered() local
1769 v4l2_device_unregister_subdev(&state->cis_sd); in s5k5baf_unregistered()
1797 static int s5k5baf_configure_gpios(struct s5k5baf *state) in s5k5baf_configure_gpios() argument
1800 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); in s5k5baf_configure_gpios()
1801 struct s5k5baf_gpio *g = state->gpios; in s5k5baf_configure_gpios()
1840 static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev) in s5k5baf_parse_device_node() argument
1853 &state->mclk_frequency); in s5k5baf_parse_device_node()
1855 state->mclk_frequency = S5K5BAF_DEFAULT_MCLK_FREQ; in s5k5baf_parse_device_node()
1857 state->mclk_frequency); in s5k5baf_parse_device_node()
1860 ret = s5k5baf_parse_gpios(state->gpios, dev); in s5k5baf_parse_device_node()
1873 state->bus_type = ep.bus_type; in s5k5baf_parse_device_node()
1875 switch (state->bus_type) { in s5k5baf_parse_device_node()
1877 state->nlanes = ep.bus.mipi_csi2.num_data_lanes; in s5k5baf_parse_device_node()
1890 static int s5k5baf_configure_subdevs(struct s5k5baf *state, in s5k5baf_configure_subdevs() argument
1896 sd = &state->cis_sd; in s5k5baf_configure_subdevs()
1899 v4l2_set_subdevdata(sd, state); in s5k5baf_configure_subdevs()
1906 state->cis_pad.flags = MEDIA_PAD_FL_SOURCE; in s5k5baf_configure_subdevs()
1908 ret = media_entity_init(&sd->entity, NUM_CIS_PADS, &state->cis_pad, 0); in s5k5baf_configure_subdevs()
1912 sd = &state->sd; in s5k5baf_configure_subdevs()
1920 state->pads[PAD_CIS].flags = MEDIA_PAD_FL_SINK; in s5k5baf_configure_subdevs()
1921 state->pads[PAD_OUT].flags = MEDIA_PAD_FL_SOURCE; in s5k5baf_configure_subdevs()
1923 ret = media_entity_init(&sd->entity, NUM_ISP_PADS, state->pads, 0); in s5k5baf_configure_subdevs()
1928 media_entity_cleanup(&state->cis_sd.entity); in s5k5baf_configure_subdevs()
1934 static int s5k5baf_configure_regulators(struct s5k5baf *state) in s5k5baf_configure_regulators() argument
1936 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); in s5k5baf_configure_regulators()
1941 state->supplies[i].supply = s5k5baf_supply_names[i]; in s5k5baf_configure_regulators()
1944 state->supplies); in s5k5baf_configure_regulators()
1953 struct s5k5baf *state; in s5k5baf_probe() local
1956 state = devm_kzalloc(&c->dev, sizeof(*state), GFP_KERNEL); in s5k5baf_probe()
1957 if (!state) in s5k5baf_probe()
1960 mutex_init(&state->lock); in s5k5baf_probe()
1961 state->crop_sink = s5k5baf_cis_rect; in s5k5baf_probe()
1962 state->compose = s5k5baf_cis_rect; in s5k5baf_probe()
1963 state->crop_source = s5k5baf_cis_rect; in s5k5baf_probe()
1965 ret = s5k5baf_parse_device_node(state, &c->dev); in s5k5baf_probe()
1969 ret = s5k5baf_configure_subdevs(state, c); in s5k5baf_probe()
1973 ret = s5k5baf_configure_gpios(state); in s5k5baf_probe()
1977 ret = s5k5baf_configure_regulators(state); in s5k5baf_probe()
1981 state->clock = devm_clk_get(state->sd.dev, S5K5BAF_CLK_NAME); in s5k5baf_probe()
1982 if (IS_ERR(state->clock)) { in s5k5baf_probe()
1987 ret = s5k5baf_power_on(state); in s5k5baf_probe()
1992 s5k5baf_hw_init(state); in s5k5baf_probe()
1993 ret = s5k5baf_check_fw_revision(state); in s5k5baf_probe()
1995 s5k5baf_power_off(state); in s5k5baf_probe()
1999 ret = s5k5baf_initialize_ctrls(state); in s5k5baf_probe()
2003 ret = v4l2_async_register_subdev(&state->sd); in s5k5baf_probe()
2010 v4l2_ctrl_handler_free(state->sd.ctrl_handler); in s5k5baf_probe()
2012 media_entity_cleanup(&state->sd.entity); in s5k5baf_probe()
2013 media_entity_cleanup(&state->cis_sd.entity); in s5k5baf_probe()
2020 struct s5k5baf *state = to_s5k5baf(sd); in s5k5baf_remove() local
2026 sd = &state->cis_sd; in s5k5baf_remove()