Lines Matching refs:mt9m111

228 struct mt9m111 {  struct
284 static const struct mt9m111_datafmt *mt9m111_find_datafmt(struct mt9m111 *mt9m111, in mt9m111_find_datafmt() argument
292 return mt9m111->fmt; in mt9m111_find_datafmt()
295 static struct mt9m111 *to_mt9m111(const struct i2c_client *client) in to_mt9m111()
297 return container_of(i2c_get_clientdata(client), struct mt9m111, subdev); in to_mt9m111()
304 struct mt9m111 *mt9m111 = to_mt9m111(client); in reg_page_map_set() local
307 if (page == mt9m111->lastpage) in reg_page_map_set()
314 mt9m111->lastpage = page; in reg_page_map_set()
375 static int mt9m111_set_context(struct mt9m111 *mt9m111, in mt9m111_set_context() argument
378 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_context()
382 static int mt9m111_setup_rect_ctx(struct mt9m111 *mt9m111, in mt9m111_setup_rect_ctx() argument
386 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_setup_rect_ctx()
397 static int mt9m111_setup_geometry(struct mt9m111 *mt9m111, struct v4l2_rect *rect, in mt9m111_setup_geometry() argument
400 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_setup_geometry()
415 ret = mt9m111_setup_rect_ctx(mt9m111, &context_b, in mt9m111_setup_geometry()
418 ret = mt9m111_setup_rect_ctx(mt9m111, &context_a, in mt9m111_setup_geometry()
429 static int mt9m111_enable(struct mt9m111 *mt9m111) in mt9m111_enable() argument
431 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_enable()
435 static int mt9m111_reset(struct mt9m111 *mt9m111) in mt9m111_reset() argument
437 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_reset()
455 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_set_selection() local
464 if (mt9m111->fmt->code == MEDIA_BUS_FMT_SBGGR8_1X8 || in mt9m111_set_selection()
465 mt9m111->fmt->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE) { in mt9m111_set_selection()
481 width = min(mt9m111->width, rect.width); in mt9m111_set_selection()
482 height = min(mt9m111->height, rect.height); in mt9m111_set_selection()
484 ret = mt9m111_setup_geometry(mt9m111, &rect, width, height, mt9m111->fmt->code); in mt9m111_set_selection()
486 mt9m111->rect = rect; in mt9m111_set_selection()
487 mt9m111->width = width; in mt9m111_set_selection()
488 mt9m111->height = height; in mt9m111_set_selection()
499 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_get_selection() local
512 sel->r = mt9m111->rect; in mt9m111_get_selection()
524 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_get_fmt() local
539 mf->width = mt9m111->width; in mt9m111_get_fmt()
540 mf->height = mt9m111->height; in mt9m111_get_fmt()
541 mf->code = mt9m111->fmt->code; in mt9m111_get_fmt()
542 mf->colorspace = mt9m111->fmt->colorspace; in mt9m111_get_fmt()
551 static int mt9m111_set_pixfmt(struct mt9m111 *mt9m111, in mt9m111_set_pixfmt() argument
554 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_pixfmt()
613 if (mt9m111->pclk_sample == 0) in mt9m111_set_pixfmt()
631 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_set_fmt() local
633 struct v4l2_rect *rect = &mt9m111->rect; in mt9m111_set_fmt()
637 if (mt9m111->is_streaming) in mt9m111_set_fmt()
643 fmt = mt9m111_find_datafmt(mt9m111, mf->code); in mt9m111_set_fmt()
684 ret = mt9m111_setup_geometry(mt9m111, rect, mf->width, mf->height, mf->code); in mt9m111_set_fmt()
686 ret = mt9m111_set_pixfmt(mt9m111, mf->code); in mt9m111_set_fmt()
688 mt9m111->width = mf->width; in mt9m111_set_fmt()
689 mt9m111->height = mf->height; in mt9m111_set_fmt()
690 mt9m111->fmt = fmt; in mt9m111_set_fmt()
697 mt9m111_find_mode(struct mt9m111 *mt9m111, unsigned int req_fps, in mt9m111_find_mode() argument
701 struct v4l2_rect *sensor_rect = &mt9m111->rect; in mt9m111_find_mode()
713 dev_info(mt9m111->subdev.dev, in mt9m111_find_mode()
721 dev_dbg(mt9m111->subdev.dev, in mt9m111_find_mode()
746 mt9m111->ctx = (best_gap_idx == MT9M111_MODE_QSXGA_30FPS) ? &context_a : in mt9m111_find_mode()
786 static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask) in mt9m111_set_flip() argument
788 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_flip()
792 ret = mt9m111_reg_set(client, mt9m111->ctx->read_mode, mask); in mt9m111_set_flip()
794 ret = mt9m111_reg_clear(client, mt9m111->ctx->read_mode, mask); in mt9m111_set_flip()
799 static int mt9m111_get_global_gain(struct mt9m111 *mt9m111) in mt9m111_get_global_gain() argument
801 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_get_global_gain()
811 static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain) in mt9m111_set_global_gain() argument
813 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_global_gain()
829 static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int val) in mt9m111_set_autoexposure() argument
831 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_autoexposure()
838 static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on) in mt9m111_set_autowhitebalance() argument
840 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_autowhitebalance()
858 static int mt9m111_set_test_pattern(struct mt9m111 *mt9m111, int val) in mt9m111_set_test_pattern() argument
860 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_test_pattern()
866 static int mt9m111_set_colorfx(struct mt9m111 *mt9m111, int val) in mt9m111_set_colorfx() argument
868 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_colorfx()
891 struct mt9m111 *mt9m111 = container_of(ctrl->handler, in mt9m111_s_ctrl() local
892 struct mt9m111, hdl); in mt9m111_s_ctrl()
896 return mt9m111_set_flip(mt9m111, ctrl->val, in mt9m111_s_ctrl()
899 return mt9m111_set_flip(mt9m111, ctrl->val, in mt9m111_s_ctrl()
902 return mt9m111_set_global_gain(mt9m111, ctrl->val); in mt9m111_s_ctrl()
904 return mt9m111_set_autoexposure(mt9m111, ctrl->val); in mt9m111_s_ctrl()
906 return mt9m111_set_autowhitebalance(mt9m111, ctrl->val); in mt9m111_s_ctrl()
908 return mt9m111_set_test_pattern(mt9m111, ctrl->val); in mt9m111_s_ctrl()
910 return mt9m111_set_colorfx(mt9m111, ctrl->val); in mt9m111_s_ctrl()
916 static int mt9m111_suspend(struct mt9m111 *mt9m111) in mt9m111_suspend() argument
918 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_suspend()
921 v4l2_ctrl_s_ctrl(mt9m111->gain, mt9m111_get_global_gain(mt9m111)); in mt9m111_suspend()
934 static void mt9m111_restore_state(struct mt9m111 *mt9m111) in mt9m111_restore_state() argument
936 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_restore_state()
938 mt9m111_set_context(mt9m111, mt9m111->ctx); in mt9m111_restore_state()
939 mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code); in mt9m111_restore_state()
940 mt9m111_setup_geometry(mt9m111, &mt9m111->rect, in mt9m111_restore_state()
941 mt9m111->width, mt9m111->height, mt9m111->fmt->code); in mt9m111_restore_state()
942 v4l2_ctrl_handler_setup(&mt9m111->hdl); in mt9m111_restore_state()
943 mt9m111_reg_mask(client, mt9m111->ctx->read_mode, in mt9m111_restore_state()
944 mt9m111->current_mode->reg_val, in mt9m111_restore_state()
945 mt9m111->current_mode->reg_mask); in mt9m111_restore_state()
948 static int mt9m111_resume(struct mt9m111 *mt9m111) in mt9m111_resume() argument
950 int ret = mt9m111_enable(mt9m111); in mt9m111_resume()
952 ret = mt9m111_reset(mt9m111); in mt9m111_resume()
954 mt9m111_restore_state(mt9m111); in mt9m111_resume()
959 static int mt9m111_init(struct mt9m111 *mt9m111) in mt9m111_init() argument
961 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_init()
964 ret = mt9m111_enable(mt9m111); in mt9m111_init()
966 ret = mt9m111_reset(mt9m111); in mt9m111_init()
968 ret = mt9m111_set_context(mt9m111, mt9m111->ctx); in mt9m111_init()
974 static int mt9m111_power_on(struct mt9m111 *mt9m111) in mt9m111_power_on() argument
976 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_power_on()
979 ret = clk_prepare_enable(mt9m111->clk); in mt9m111_power_on()
983 ret = regulator_enable(mt9m111->regulator); in mt9m111_power_on()
987 ret = mt9m111_resume(mt9m111); in mt9m111_power_on()
994 regulator_disable(mt9m111->regulator); in mt9m111_power_on()
997 clk_disable_unprepare(mt9m111->clk); in mt9m111_power_on()
1004 static void mt9m111_power_off(struct mt9m111 *mt9m111) in mt9m111_power_off() argument
1006 mt9m111_suspend(mt9m111); in mt9m111_power_off()
1007 regulator_disable(mt9m111->regulator); in mt9m111_power_off()
1008 clk_disable_unprepare(mt9m111->clk); in mt9m111_power_off()
1013 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_s_power() local
1016 mutex_lock(&mt9m111->power_lock); in mt9m111_s_power()
1022 if (mt9m111->power_count == !on) { in mt9m111_s_power()
1024 ret = mt9m111_power_on(mt9m111); in mt9m111_s_power()
1026 mt9m111_power_off(mt9m111); in mt9m111_s_power()
1031 mt9m111->power_count += on ? 1 : -1; in mt9m111_s_power()
1032 WARN_ON(mt9m111->power_count < 0); in mt9m111_s_power()
1035 mutex_unlock(&mt9m111->power_lock); in mt9m111_s_power()
1057 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_g_frame_interval() local
1059 fi->interval = mt9m111->frame_interval; in mt9m111_g_frame_interval()
1067 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_s_frame_interval() local
1072 if (mt9m111->is_streaming) in mt9m111_s_frame_interval()
1086 mode = mt9m111_find_mode(mt9m111, fps, mt9m111->width, mt9m111->height); in mt9m111_s_frame_interval()
1095 mt9m111->current_mode = mode; in mt9m111_s_frame_interval()
1096 mt9m111->frame_interval = fi->interval; in mt9m111_s_frame_interval()
1114 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_s_stream() local
1116 mt9m111->is_streaming = !!enable; in mt9m111_s_stream()
1143 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_get_mbus_config() local
1152 cfg->bus.parallel.flags |= mt9m111->pclk_sample ? in mt9m111_get_mbus_config()
1187 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_video_probe() local
1191 ret = mt9m111_s_power(&mt9m111->subdev, 1); in mt9m111_video_probe()
1213 ret = mt9m111_init(mt9m111); in mt9m111_video_probe()
1217 ret = v4l2_ctrl_handler_setup(&mt9m111->hdl); in mt9m111_video_probe()
1220 mt9m111_s_power(&mt9m111->subdev, 0); in mt9m111_video_probe()
1224 static int mt9m111_probe_fw(struct i2c_client *client, struct mt9m111 *mt9m111) in mt9m111_probe_fw() argument
1240 mt9m111->pclk_sample = !!(bus_cfg.bus.parallel.flags & in mt9m111_probe_fw()
1250 struct mt9m111 *mt9m111; in mt9m111_probe() local
1260 mt9m111 = devm_kzalloc(&client->dev, sizeof(struct mt9m111), GFP_KERNEL); in mt9m111_probe()
1261 if (!mt9m111) in mt9m111_probe()
1265 ret = mt9m111_probe_fw(client, mt9m111); in mt9m111_probe()
1270 mt9m111->clk = devm_clk_get(&client->dev, "mclk"); in mt9m111_probe()
1271 if (IS_ERR(mt9m111->clk)) in mt9m111_probe()
1272 return PTR_ERR(mt9m111->clk); in mt9m111_probe()
1274 mt9m111->regulator = devm_regulator_get(&client->dev, "vdd"); in mt9m111_probe()
1275 if (IS_ERR(mt9m111->regulator)) { in mt9m111_probe()
1277 PTR_ERR(mt9m111->regulator)); in mt9m111_probe()
1278 return PTR_ERR(mt9m111->regulator); in mt9m111_probe()
1282 mt9m111->ctx = &context_b; in mt9m111_probe()
1284 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops); in mt9m111_probe()
1285 mt9m111->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in mt9m111_probe()
1288 v4l2_ctrl_handler_init(&mt9m111->hdl, 7); in mt9m111_probe()
1289 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1291 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1293 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1295 mt9m111->gain = v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1297 v4l2_ctrl_new_std_menu(&mt9m111->hdl, in mt9m111_probe()
1300 v4l2_ctrl_new_std_menu_items(&mt9m111->hdl, in mt9m111_probe()
1304 v4l2_ctrl_new_std_menu(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1312 mt9m111->subdev.ctrl_handler = &mt9m111->hdl; in mt9m111_probe()
1313 if (mt9m111->hdl.error) { in mt9m111_probe()
1314 ret = mt9m111->hdl.error; in mt9m111_probe()
1319 mt9m111->pad.flags = MEDIA_PAD_FL_SOURCE; in mt9m111_probe()
1320 mt9m111->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in mt9m111_probe()
1321 ret = media_entity_pads_init(&mt9m111->subdev.entity, 1, &mt9m111->pad); in mt9m111_probe()
1326 mt9m111->current_mode = &mt9m111_mode_data[MT9M111_MODE_SXGA_15FPS]; in mt9m111_probe()
1327 mt9m111->frame_interval.numerator = 1; in mt9m111_probe()
1328 mt9m111->frame_interval.denominator = mt9m111->current_mode->max_fps; in mt9m111_probe()
1331 mt9m111->rect.left = MT9M111_MIN_DARK_COLS; in mt9m111_probe()
1332 mt9m111->rect.top = MT9M111_MIN_DARK_ROWS; in mt9m111_probe()
1333 mt9m111->rect.width = MT9M111_MAX_WIDTH; in mt9m111_probe()
1334 mt9m111->rect.height = MT9M111_MAX_HEIGHT; in mt9m111_probe()
1335 mt9m111->width = mt9m111->rect.width; in mt9m111_probe()
1336 mt9m111->height = mt9m111->rect.height; in mt9m111_probe()
1337 mt9m111->fmt = &mt9m111_colour_fmts[0]; in mt9m111_probe()
1338 mt9m111->lastpage = -1; in mt9m111_probe()
1339 mutex_init(&mt9m111->power_lock); in mt9m111_probe()
1345 mt9m111->subdev.dev = &client->dev; in mt9m111_probe()
1346 ret = v4l2_async_register_subdev(&mt9m111->subdev); in mt9m111_probe()
1354 media_entity_cleanup(&mt9m111->subdev.entity); in mt9m111_probe()
1357 v4l2_ctrl_handler_free(&mt9m111->hdl); in mt9m111_probe()
1364 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_remove() local
1366 v4l2_async_unregister_subdev(&mt9m111->subdev); in mt9m111_remove()
1367 media_entity_cleanup(&mt9m111->subdev.entity); in mt9m111_remove()
1368 v4l2_ctrl_handler_free(&mt9m111->hdl); in mt9m111_remove()