Lines Matching refs:hi556
138 struct hi556 { struct
174 #define to_hi556(sd) container_of(sd, struct hi556, subdev) argument
617 hi556_find_best_fit(struct hi556 *hi556, in hi556_find_best_fit() argument
626 for (i = 0; i < hi556->cfg_num; i++) { in hi556_find_best_fit()
641 struct hi556 *hi556 = to_hi556(sd); in hi556_set_fmt() local
645 mutex_lock(&hi556->mutex); in hi556_set_fmt()
647 mode = hi556_find_best_fit(hi556, fmt); in hi556_set_fmt()
656 mutex_unlock(&hi556->mutex); in hi556_set_fmt()
660 hi556->cur_mode = mode; in hi556_set_fmt()
662 __v4l2_ctrl_modify_range(hi556->hblank, h_blank, in hi556_set_fmt()
665 __v4l2_ctrl_modify_range(hi556->vblank, vblank_def, in hi556_set_fmt()
670 mutex_unlock(&hi556->mutex); in hi556_set_fmt()
679 struct hi556 *hi556 = to_hi556(sd); in hi556_get_fmt() local
680 const struct hi556_mode *mode = hi556->cur_mode; in hi556_get_fmt()
682 mutex_lock(&hi556->mutex); in hi556_get_fmt()
687 mutex_unlock(&hi556->mutex); in hi556_get_fmt()
696 mutex_unlock(&hi556->mutex); in hi556_get_fmt()
716 struct hi556 *hi556 = to_hi556(sd); in hi556_enum_frame_sizes() local
718 if (fse->index >= hi556->cfg_num) in hi556_enum_frame_sizes()
732 static int hi556_enable_test_pattern(struct hi556 *hi556, u32 pattern) in hi556_enable_test_pattern() argument
736 hi556_write_reg(hi556->client, HI556_REG_TEST_PATTERN, in hi556_enable_test_pattern()
738 hi556_write_reg(hi556->client, HI556_REG_TEST_PATTERN_SELECT, in hi556_enable_test_pattern()
741 hi556_write_reg(hi556->client, HI556_REG_TEST_PATTERN, in hi556_enable_test_pattern()
750 struct hi556 *hi556 = to_hi556(sd); in hi556_g_frame_interval() local
751 const struct hi556_mode *mode = hi556->cur_mode; in hi556_g_frame_interval()
772 static void hi556_get_module_inf(struct hi556 *hi556, in hi556_get_module_inf() argument
777 strscpy(inf->base.module, hi556->module_name, in hi556_get_module_inf()
779 strscpy(inf->base.lens, hi556->len_name, sizeof(inf->base.lens)); in hi556_get_module_inf()
783 static void hi556_set_awb_cfg(struct hi556 *hi556, in hi556_set_awb_cfg() argument
786 mutex_lock(&hi556->mutex); in hi556_set_awb_cfg()
787 memcpy(&hi556->awb_cfg, cfg, sizeof(*cfg)); in hi556_set_awb_cfg()
788 mutex_unlock(&hi556->mutex); in hi556_set_awb_cfg()
793 struct hi556 *hi556 = to_hi556(sd); in hi556_ioctl() local
799 hi556_get_module_inf(hi556, (struct rkmodule_inf *)arg); in hi556_ioctl()
802 hi556_set_awb_cfg(hi556, (struct rkmodule_awb_cfg *)arg); in hi556_ioctl()
809 ret = hi556_write_reg(hi556->client, HI556_REG_CTRL_MODE, in hi556_ioctl()
812 ret = hi556_write_reg(hi556->client, HI556_REG_CTRL_MODE, in hi556_ioctl()
877 static int __hi556_start_stream(struct hi556 *hi556) in __hi556_start_stream() argument
881 ret = hi556_write_array(hi556->client, hi556->cur_mode->reg_list); in __hi556_start_stream()
889 dev_info(&hi556->client->dev, "%s:Check register value!\n", in __hi556_start_stream()
891 ret = hi556_reg_verify(hi556->client, hi556_global_regs); in __hi556_start_stream()
895 ret = hi556_reg_verify(hi556->client, hi556->cur_mode->reg_list); in __hi556_start_stream()
901 mutex_unlock(&hi556->mutex); in __hi556_start_stream()
902 ret = v4l2_ctrl_handler_setup(&hi556->ctrl_handler); in __hi556_start_stream()
903 mutex_lock(&hi556->mutex); in __hi556_start_stream()
908 dev_info(&hi556->client->dev, "APPly otp failed!\n"); in __hi556_start_stream()
910 ret = hi556_write_reg(hi556->client, HI556_REG_CTRL_MODE, in __hi556_start_stream()
915 static int __hi556_stop_stream(struct hi556 *hi556) in __hi556_stop_stream() argument
917 return hi556_write_reg(hi556->client, HI556_REG_CTRL_MODE, in __hi556_stop_stream()
923 struct hi556 *hi556 = to_hi556(sd); in hi556_s_stream() local
924 struct i2c_client *client = hi556->client; in hi556_s_stream()
928 hi556->cur_mode->width, in hi556_s_stream()
929 hi556->cur_mode->height, in hi556_s_stream()
930 DIV_ROUND_CLOSEST(hi556->cur_mode->max_fps.denominator, in hi556_s_stream()
931 hi556->cur_mode->max_fps.numerator)); in hi556_s_stream()
933 mutex_lock(&hi556->mutex); in hi556_s_stream()
935 if (on == hi556->streaming) in hi556_s_stream()
946 ret = __hi556_start_stream(hi556); in hi556_s_stream()
954 __hi556_stop_stream(hi556); in hi556_s_stream()
958 hi556->streaming = on; in hi556_s_stream()
961 mutex_unlock(&hi556->mutex); in hi556_s_stream()
968 struct hi556 *hi556 = to_hi556(sd); in hi556_s_power() local
969 struct i2c_client *client = hi556->client; in hi556_s_power()
973 mutex_lock(&hi556->mutex); in hi556_s_power()
976 if (hi556->power_on == !!on) in hi556_s_power()
986 ret = hi556_write_array(hi556->client, hi556_global_regs); in hi556_s_power()
993 hi556->power_on = true; in hi556_s_power()
996 hi556->power_on = false; in hi556_s_power()
1000 mutex_unlock(&hi556->mutex); in hi556_s_power()
1011 static int __hi556_power_on(struct hi556 *hi556) in __hi556_power_on() argument
1015 struct device *dev = &hi556->client->dev; in __hi556_power_on()
1017 if (!IS_ERR(hi556->power_gpio)) in __hi556_power_on()
1018 gpiod_set_value_cansleep(hi556->power_gpio, 1); in __hi556_power_on()
1022 if (!IS_ERR_OR_NULL(hi556->pins_default)) { in __hi556_power_on()
1023 ret = pinctrl_select_state(hi556->pinctrl, in __hi556_power_on()
1024 hi556->pins_default); in __hi556_power_on()
1028 ret = clk_set_rate(hi556->xvclk, HI556_XVCLK_FREQ); in __hi556_power_on()
1031 if (clk_get_rate(hi556->xvclk) != HI556_XVCLK_FREQ) in __hi556_power_on()
1034 ret = clk_prepare_enable(hi556->xvclk); in __hi556_power_on()
1040 ret = regulator_bulk_enable(HI556_NUM_SUPPLIES, hi556->supplies); in __hi556_power_on()
1046 if (!IS_ERR(hi556->reset_gpio)) in __hi556_power_on()
1047 gpiod_set_value_cansleep(hi556->reset_gpio, 1); in __hi556_power_on()
1049 if (!IS_ERR(hi556->pwdn_gpio)) in __hi556_power_on()
1050 gpiod_set_value_cansleep(hi556->pwdn_gpio, 1); in __hi556_power_on()
1059 clk_disable_unprepare(hi556->xvclk); in __hi556_power_on()
1064 static void __hi556_power_off(struct hi556 *hi556) in __hi556_power_off() argument
1067 struct device *dev = &hi556->client->dev; in __hi556_power_off()
1069 if (!IS_ERR(hi556->pwdn_gpio)) in __hi556_power_off()
1070 gpiod_set_value_cansleep(hi556->pwdn_gpio, 0); in __hi556_power_off()
1071 clk_disable_unprepare(hi556->xvclk); in __hi556_power_off()
1072 if (!IS_ERR(hi556->reset_gpio)) in __hi556_power_off()
1073 gpiod_set_value_cansleep(hi556->reset_gpio, 0); in __hi556_power_off()
1074 if (!IS_ERR_OR_NULL(hi556->pins_sleep)) { in __hi556_power_off()
1075 ret = pinctrl_select_state(hi556->pinctrl, in __hi556_power_off()
1076 hi556->pins_sleep); in __hi556_power_off()
1080 if (!IS_ERR(hi556->power_gpio)) in __hi556_power_off()
1081 gpiod_set_value_cansleep(hi556->power_gpio, 0); in __hi556_power_off()
1083 regulator_bulk_disable(HI556_NUM_SUPPLIES, hi556->supplies); in __hi556_power_off()
1090 struct hi556 *hi556 = to_hi556(sd); in hi556_runtime_resume() local
1092 return __hi556_power_on(hi556); in hi556_runtime_resume()
1099 struct hi556 *hi556 = to_hi556(sd); in hi556_runtime_suspend() local
1101 __hi556_power_off(hi556); in hi556_runtime_suspend()
1109 struct hi556 *hi556 = to_hi556(sd); in hi556_open() local
1114 mutex_lock(&hi556->mutex); in hi556_open()
1121 mutex_unlock(&hi556->mutex); in hi556_open()
1132 struct hi556 *hi556 = to_hi556(sd); in hi556_enum_frame_interval() local
1134 if (fie->index >= hi556->cfg_num) in hi556_enum_frame_interval()
1187 static int hi556_set_exposure_reg(struct hi556 *hi556, u32 exposure) in hi556_set_exposure_reg() argument
1195 ret = hi556_write_reg(hi556->client, HI556_REG_GROUP, in hi556_set_exposure_reg()
1197 ret |= hi556_write_reg(hi556->client, in hi556_set_exposure_reg()
1201 ret |= hi556_write_reg(hi556->client, in hi556_set_exposure_reg()
1205 ret |= hi556_write_reg(hi556->client, in hi556_set_exposure_reg()
1209 ret |= hi556_write_reg(hi556->client, HI556_REG_GROUP, in hi556_set_exposure_reg()
1215 static int hi556_set_gain_reg(struct hi556 *hi556, u32 a_gain) in hi556_set_gain_reg() argument
1219 ret = hi556_write_reg(hi556->client, HI556_REG_GROUP, in hi556_set_gain_reg()
1221 ret |= hi556_write_reg(hi556->client, HI556_REG_GAIN, in hi556_set_gain_reg()
1223 ret |= hi556_write_reg(hi556->client, HI556_REG_GROUP, in hi556_set_gain_reg()
1231 struct hi556 *hi556 = container_of(ctrl->handler, in hi556_set_ctrl() local
1232 struct hi556, ctrl_handler); in hi556_set_ctrl()
1233 struct i2c_client *client = hi556->client; in hi556_set_ctrl()
1242 max = hi556->cur_mode->height + ctrl->val - 4; in hi556_set_ctrl()
1243 __v4l2_ctrl_modify_range(hi556->exposure, in hi556_set_ctrl()
1244 hi556->exposure->minimum, max, in hi556_set_ctrl()
1245 hi556->exposure->step, in hi556_set_ctrl()
1246 hi556->exposure->default_value); in hi556_set_ctrl()
1257 ret = hi556_set_exposure_reg(hi556, ctrl->val); in hi556_set_ctrl()
1261 ret = hi556_set_gain_reg(hi556, ctrl->val); in hi556_set_ctrl()
1265 ret = hi556_write_reg(hi556->client, HI556_REG_VTS, in hi556_set_ctrl()
1267 ctrl->val + hi556->cur_mode->height); in hi556_set_ctrl()
1270 ret = hi556_enable_test_pattern(hi556, ctrl->val); in hi556_set_ctrl()
1273 ret = hi556_read_reg(hi556->client, HI556_FLIP_MIRROR_REG, in hi556_set_ctrl()
1275 ret |= hi556_write_reg(hi556->client, HI556_FLIP_MIRROR_REG, in hi556_set_ctrl()
1280 ret = hi556_read_reg(hi556->client, HI556_FLIP_MIRROR_REG, in hi556_set_ctrl()
1282 ret |= hi556_write_reg(hi556->client, HI556_FLIP_MIRROR_REG, in hi556_set_ctrl()
1301 static int hi556_initialize_controls(struct hi556 *hi556) in hi556_initialize_controls() argument
1310 handler = &hi556->ctrl_handler; in hi556_initialize_controls()
1311 mode = hi556->cur_mode; in hi556_initialize_controls()
1315 handler->lock = &hi556->mutex; in hi556_initialize_controls()
1323 0, hi556->pixel_rate, 1, hi556->pixel_rate); in hi556_initialize_controls()
1326 hi556->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in hi556_initialize_controls()
1328 if (hi556->hblank) in hi556_initialize_controls()
1329 hi556->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in hi556_initialize_controls()
1332 hi556->vblank = v4l2_ctrl_new_std(handler, &hi556_ctrl_ops, in hi556_initialize_controls()
1338 hi556->exposure = v4l2_ctrl_new_std(handler, &hi556_ctrl_ops, in hi556_initialize_controls()
1343 hi556->anal_gain = v4l2_ctrl_new_std(handler, &hi556_ctrl_ops, in hi556_initialize_controls()
1348 hi556->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in hi556_initialize_controls()
1360 dev_err(&hi556->client->dev, in hi556_initialize_controls()
1365 hi556->subdev.ctrl_handler = handler; in hi556_initialize_controls()
1375 static int hi556_check_sensor_id(struct hi556 *hi556, in hi556_check_sensor_id() argument
1378 struct device *dev = &hi556->client->dev; in hi556_check_sensor_id()
1394 static int hi556_configure_regulators(struct hi556 *hi556) in hi556_configure_regulators() argument
1399 hi556->supplies[i].supply = hi556_supply_names[i]; in hi556_configure_regulators()
1401 return devm_regulator_bulk_get(&hi556->client->dev, in hi556_configure_regulators()
1403 hi556->supplies); in hi556_configure_regulators()
1406 static int hi556_parse_of(struct hi556 *hi556) in hi556_parse_of() argument
1408 struct device *dev = &hi556->client->dev; in hi556_parse_of()
1425 hi556->lane_num = rval; in hi556_parse_of()
1426 if (hi556->lane_num == 2) { in hi556_parse_of()
1427 hi556->cur_mode = &supported_modes_2lane[0]; in hi556_parse_of()
1429 hi556->cfg_num = ARRAY_SIZE(supported_modes_2lane); in hi556_parse_of()
1432 hi556->pixel_rate = MIPI_FREQ * 2U * hi556->lane_num / 8U; in hi556_parse_of()
1434 hi556->lane_num, hi556->pixel_rate); in hi556_parse_of()
1436 dev_err(dev, "unsupported lane_num(%d)\n", hi556->lane_num); in hi556_parse_of()
1448 struct hi556 *hi556; in hi556_probe() local
1458 hi556 = devm_kzalloc(dev, sizeof(*hi556), GFP_KERNEL); in hi556_probe()
1459 if (!hi556) in hi556_probe()
1463 &hi556->module_index); in hi556_probe()
1466 hi556->module_index = 0; in hi556_probe()
1469 &hi556->module_facing); in hi556_probe()
1471 &hi556->module_name); in hi556_probe()
1473 &hi556->len_name); in hi556_probe()
1479 hi556->client = client; in hi556_probe()
1481 hi556->xvclk = devm_clk_get(dev, "xvclk"); in hi556_probe()
1482 if (IS_ERR(hi556->xvclk)) { in hi556_probe()
1487 hi556->power_gpio = devm_gpiod_get(dev, "power", GPIOD_OUT_LOW); in hi556_probe()
1488 if (IS_ERR(hi556->power_gpio)) in hi556_probe()
1491 hi556->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in hi556_probe()
1492 if (IS_ERR(hi556->reset_gpio)) in hi556_probe()
1495 hi556->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in hi556_probe()
1496 if (IS_ERR(hi556->pwdn_gpio)) in hi556_probe()
1499 ret = hi556_configure_regulators(hi556); in hi556_probe()
1504 ret = hi556_parse_of(hi556); in hi556_probe()
1508 hi556->pinctrl = devm_pinctrl_get(dev); in hi556_probe()
1509 if (!IS_ERR(hi556->pinctrl)) { in hi556_probe()
1510 hi556->pins_default = in hi556_probe()
1511 pinctrl_lookup_state(hi556->pinctrl, in hi556_probe()
1513 if (IS_ERR(hi556->pins_default)) in hi556_probe()
1516 hi556->pins_sleep = in hi556_probe()
1517 pinctrl_lookup_state(hi556->pinctrl, in hi556_probe()
1519 if (IS_ERR(hi556->pins_sleep)) in hi556_probe()
1523 mutex_init(&hi556->mutex); in hi556_probe()
1525 sd = &hi556->subdev; in hi556_probe()
1527 ret = hi556_initialize_controls(hi556); in hi556_probe()
1531 ret = __hi556_power_on(hi556); in hi556_probe()
1535 ret = hi556_check_sensor_id(hi556, client); in hi556_probe()
1550 hi556->pad.flags = MEDIA_PAD_FL_SOURCE; in hi556_probe()
1552 ret = media_entity_pads_init(&sd->entity, 1, &hi556->pad); in hi556_probe()
1558 if (strcmp(hi556->module_facing, "back") == 0) in hi556_probe()
1564 hi556->module_index, facing, in hi556_probe()
1584 __hi556_power_off(hi556); in hi556_probe()
1586 v4l2_ctrl_handler_free(&hi556->ctrl_handler); in hi556_probe()
1588 mutex_destroy(&hi556->mutex); in hi556_probe()
1596 struct hi556 *hi556 = to_hi556(sd); in hi556_remove() local
1602 v4l2_ctrl_handler_free(&hi556->ctrl_handler); in hi556_remove()
1603 mutex_destroy(&hi556->mutex); in hi556_remove()
1607 __hi556_power_off(hi556); in hi556_remove()