Lines Matching refs:mt9m111

229 struct mt9m111 {  struct
285 static const struct mt9m111_datafmt *mt9m111_find_datafmt(struct mt9m111 *mt9m111, in mt9m111_find_datafmt() argument
293 return mt9m111->fmt; in mt9m111_find_datafmt()
296 static struct mt9m111 *to_mt9m111(const struct i2c_client *client) in to_mt9m111()
298 return container_of(i2c_get_clientdata(client), struct mt9m111, subdev); in to_mt9m111()
305 struct mt9m111 *mt9m111 = to_mt9m111(client); in reg_page_map_set() local
308 if (page == mt9m111->lastpage) in reg_page_map_set()
315 mt9m111->lastpage = page; in reg_page_map_set()
376 static int mt9m111_set_context(struct mt9m111 *mt9m111, in mt9m111_set_context() argument
379 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_context()
383 static int mt9m111_setup_rect_ctx(struct mt9m111 *mt9m111, in mt9m111_setup_rect_ctx() argument
387 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_setup_rect_ctx()
398 static int mt9m111_setup_geometry(struct mt9m111 *mt9m111, struct v4l2_rect *rect, in mt9m111_setup_geometry() argument
401 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_setup_geometry()
416 ret = mt9m111_setup_rect_ctx(mt9m111, &context_b, in mt9m111_setup_geometry()
419 ret = mt9m111_setup_rect_ctx(mt9m111, &context_a, in mt9m111_setup_geometry()
430 static int mt9m111_enable(struct mt9m111 *mt9m111) in mt9m111_enable() argument
432 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_enable()
436 static int mt9m111_reset(struct mt9m111 *mt9m111) in mt9m111_reset() argument
438 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_reset()
456 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_set_selection() local
465 if (mt9m111->fmt->code == MEDIA_BUS_FMT_SBGGR8_1X8 || in mt9m111_set_selection()
466 mt9m111->fmt->code == MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE) { in mt9m111_set_selection()
482 width = min(mt9m111->width, rect.width); in mt9m111_set_selection()
483 height = min(mt9m111->height, rect.height); in mt9m111_set_selection()
485 ret = mt9m111_setup_geometry(mt9m111, &rect, width, height, mt9m111->fmt->code); in mt9m111_set_selection()
487 mt9m111->rect = rect; in mt9m111_set_selection()
488 mt9m111->width = width; in mt9m111_set_selection()
489 mt9m111->height = height; in mt9m111_set_selection()
500 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_get_selection() local
513 sel->r = mt9m111->rect; in mt9m111_get_selection()
525 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_get_fmt() local
540 mf->width = mt9m111->width; in mt9m111_get_fmt()
541 mf->height = mt9m111->height; in mt9m111_get_fmt()
542 mf->code = mt9m111->fmt->code; in mt9m111_get_fmt()
543 mf->colorspace = mt9m111->fmt->colorspace; in mt9m111_get_fmt()
552 static int mt9m111_set_pixfmt(struct mt9m111 *mt9m111, in mt9m111_set_pixfmt() argument
555 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_pixfmt()
614 if (mt9m111->pclk_sample == 0) in mt9m111_set_pixfmt()
632 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_set_fmt() local
634 struct v4l2_rect *rect = &mt9m111->rect; in mt9m111_set_fmt()
638 if (mt9m111->is_streaming) in mt9m111_set_fmt()
644 fmt = mt9m111_find_datafmt(mt9m111, mf->code); in mt9m111_set_fmt()
685 ret = mt9m111_setup_geometry(mt9m111, rect, mf->width, mf->height, mf->code); in mt9m111_set_fmt()
687 ret = mt9m111_set_pixfmt(mt9m111, mf->code); in mt9m111_set_fmt()
689 mt9m111->width = mf->width; in mt9m111_set_fmt()
690 mt9m111->height = mf->height; in mt9m111_set_fmt()
691 mt9m111->fmt = fmt; in mt9m111_set_fmt()
698 mt9m111_find_mode(struct mt9m111 *mt9m111, unsigned int req_fps, in mt9m111_find_mode() argument
702 struct v4l2_rect *sensor_rect = &mt9m111->rect; in mt9m111_find_mode()
714 dev_info(mt9m111->subdev.dev, in mt9m111_find_mode()
722 dev_dbg(mt9m111->subdev.dev, in mt9m111_find_mode()
747 mt9m111->ctx = (best_gap_idx == MT9M111_MODE_QSXGA_30FPS) ? &context_a : in mt9m111_find_mode()
787 static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask) in mt9m111_set_flip() argument
789 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_flip()
793 ret = mt9m111_reg_set(client, mt9m111->ctx->read_mode, mask); in mt9m111_set_flip()
795 ret = mt9m111_reg_clear(client, mt9m111->ctx->read_mode, mask); in mt9m111_set_flip()
800 static int mt9m111_get_global_gain(struct mt9m111 *mt9m111) in mt9m111_get_global_gain() argument
802 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_get_global_gain()
812 static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain) in mt9m111_set_global_gain() argument
814 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_global_gain()
830 static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int val) in mt9m111_set_autoexposure() argument
832 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_autoexposure()
839 static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on) in mt9m111_set_autowhitebalance() argument
841 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_autowhitebalance()
859 static int mt9m111_set_test_pattern(struct mt9m111 *mt9m111, int val) in mt9m111_set_test_pattern() argument
861 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_test_pattern()
867 static int mt9m111_set_colorfx(struct mt9m111 *mt9m111, int val) in mt9m111_set_colorfx() argument
869 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_set_colorfx()
892 struct mt9m111 *mt9m111 = container_of(ctrl->handler, in mt9m111_s_ctrl() local
893 struct mt9m111, hdl); in mt9m111_s_ctrl()
897 return mt9m111_set_flip(mt9m111, ctrl->val, in mt9m111_s_ctrl()
900 return mt9m111_set_flip(mt9m111, ctrl->val, in mt9m111_s_ctrl()
903 return mt9m111_set_global_gain(mt9m111, ctrl->val); in mt9m111_s_ctrl()
905 return mt9m111_set_autoexposure(mt9m111, ctrl->val); in mt9m111_s_ctrl()
907 return mt9m111_set_autowhitebalance(mt9m111, ctrl->val); in mt9m111_s_ctrl()
909 return mt9m111_set_test_pattern(mt9m111, ctrl->val); in mt9m111_s_ctrl()
911 return mt9m111_set_colorfx(mt9m111, ctrl->val); in mt9m111_s_ctrl()
917 static int mt9m111_suspend(struct mt9m111 *mt9m111) in mt9m111_suspend() argument
919 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_suspend()
922 v4l2_ctrl_s_ctrl(mt9m111->gain, mt9m111_get_global_gain(mt9m111)); in mt9m111_suspend()
935 static void mt9m111_restore_state(struct mt9m111 *mt9m111) in mt9m111_restore_state() argument
937 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_restore_state()
939 mt9m111_set_context(mt9m111, mt9m111->ctx); in mt9m111_restore_state()
940 mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code); in mt9m111_restore_state()
941 mt9m111_setup_geometry(mt9m111, &mt9m111->rect, in mt9m111_restore_state()
942 mt9m111->width, mt9m111->height, mt9m111->fmt->code); in mt9m111_restore_state()
943 v4l2_ctrl_handler_setup(&mt9m111->hdl); in mt9m111_restore_state()
944 mt9m111_reg_mask(client, mt9m111->ctx->read_mode, in mt9m111_restore_state()
945 mt9m111->current_mode->reg_val, in mt9m111_restore_state()
946 mt9m111->current_mode->reg_mask); in mt9m111_restore_state()
949 static int mt9m111_resume(struct mt9m111 *mt9m111) in mt9m111_resume() argument
951 int ret = mt9m111_enable(mt9m111); in mt9m111_resume()
953 ret = mt9m111_reset(mt9m111); in mt9m111_resume()
955 mt9m111_restore_state(mt9m111); in mt9m111_resume()
960 static int mt9m111_init(struct mt9m111 *mt9m111) in mt9m111_init() argument
962 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_init()
965 ret = mt9m111_enable(mt9m111); in mt9m111_init()
967 ret = mt9m111_reset(mt9m111); in mt9m111_init()
969 ret = mt9m111_set_context(mt9m111, mt9m111->ctx); in mt9m111_init()
975 static int mt9m111_power_on(struct mt9m111 *mt9m111) in mt9m111_power_on() argument
977 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); in mt9m111_power_on()
980 ret = v4l2_clk_enable(mt9m111->clk); in mt9m111_power_on()
984 ret = regulator_enable(mt9m111->regulator); in mt9m111_power_on()
988 ret = mt9m111_resume(mt9m111); in mt9m111_power_on()
995 regulator_disable(mt9m111->regulator); in mt9m111_power_on()
998 v4l2_clk_disable(mt9m111->clk); in mt9m111_power_on()
1005 static void mt9m111_power_off(struct mt9m111 *mt9m111) in mt9m111_power_off() argument
1007 mt9m111_suspend(mt9m111); in mt9m111_power_off()
1008 regulator_disable(mt9m111->regulator); in mt9m111_power_off()
1009 v4l2_clk_disable(mt9m111->clk); in mt9m111_power_off()
1014 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_s_power() local
1017 mutex_lock(&mt9m111->power_lock); in mt9m111_s_power()
1023 if (mt9m111->power_count == !on) { in mt9m111_s_power()
1025 ret = mt9m111_power_on(mt9m111); in mt9m111_s_power()
1027 mt9m111_power_off(mt9m111); in mt9m111_s_power()
1032 mt9m111->power_count += on ? 1 : -1; in mt9m111_s_power()
1033 WARN_ON(mt9m111->power_count < 0); in mt9m111_s_power()
1036 mutex_unlock(&mt9m111->power_lock); in mt9m111_s_power()
1058 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_g_frame_interval() local
1060 fi->interval = mt9m111->frame_interval; in mt9m111_g_frame_interval()
1068 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_s_frame_interval() local
1073 if (mt9m111->is_streaming) in mt9m111_s_frame_interval()
1087 mode = mt9m111_find_mode(mt9m111, fps, mt9m111->width, mt9m111->height); in mt9m111_s_frame_interval()
1096 mt9m111->current_mode = mode; in mt9m111_s_frame_interval()
1097 mt9m111->frame_interval = fi->interval; in mt9m111_s_frame_interval()
1115 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_s_stream() local
1117 mt9m111->is_streaming = !!enable; in mt9m111_s_stream()
1144 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); in mt9m111_get_mbus_config() local
1150 cfg->flags |= mt9m111->pclk_sample ? V4L2_MBUS_PCLK_SAMPLE_RISING : in mt9m111_get_mbus_config()
1186 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_video_probe() local
1190 ret = mt9m111_s_power(&mt9m111->subdev, 1); in mt9m111_video_probe()
1212 ret = mt9m111_init(mt9m111); in mt9m111_video_probe()
1216 ret = v4l2_ctrl_handler_setup(&mt9m111->hdl); in mt9m111_video_probe()
1219 mt9m111_s_power(&mt9m111->subdev, 0); in mt9m111_video_probe()
1223 static int mt9m111_probe_fw(struct i2c_client *client, struct mt9m111 *mt9m111) in mt9m111_probe_fw() argument
1239 mt9m111->pclk_sample = !!(bus_cfg.bus.parallel.flags & in mt9m111_probe_fw()
1249 struct mt9m111 *mt9m111; in mt9m111_probe() local
1259 mt9m111 = devm_kzalloc(&client->dev, sizeof(struct mt9m111), GFP_KERNEL); in mt9m111_probe()
1260 if (!mt9m111) in mt9m111_probe()
1264 ret = mt9m111_probe_fw(client, mt9m111); in mt9m111_probe()
1269 mt9m111->clk = v4l2_clk_get(&client->dev, "mclk"); in mt9m111_probe()
1270 if (IS_ERR(mt9m111->clk)) in mt9m111_probe()
1271 return PTR_ERR(mt9m111->clk); in mt9m111_probe()
1273 mt9m111->regulator = devm_regulator_get(&client->dev, "vdd"); in mt9m111_probe()
1274 if (IS_ERR(mt9m111->regulator)) { in mt9m111_probe()
1276 PTR_ERR(mt9m111->regulator)); in mt9m111_probe()
1277 return PTR_ERR(mt9m111->regulator); in mt9m111_probe()
1281 mt9m111->ctx = &context_b; in mt9m111_probe()
1283 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops); in mt9m111_probe()
1284 mt9m111->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in mt9m111_probe()
1287 v4l2_ctrl_handler_init(&mt9m111->hdl, 7); in mt9m111_probe()
1288 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1290 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1292 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1294 mt9m111->gain = v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1296 v4l2_ctrl_new_std_menu(&mt9m111->hdl, in mt9m111_probe()
1299 v4l2_ctrl_new_std_menu_items(&mt9m111->hdl, in mt9m111_probe()
1303 v4l2_ctrl_new_std_menu(&mt9m111->hdl, &mt9m111_ctrl_ops, in mt9m111_probe()
1311 mt9m111->subdev.ctrl_handler = &mt9m111->hdl; in mt9m111_probe()
1312 if (mt9m111->hdl.error) { in mt9m111_probe()
1313 ret = mt9m111->hdl.error; in mt9m111_probe()
1318 mt9m111->pad.flags = MEDIA_PAD_FL_SOURCE; in mt9m111_probe()
1319 mt9m111->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in mt9m111_probe()
1320 ret = media_entity_pads_init(&mt9m111->subdev.entity, 1, &mt9m111->pad); in mt9m111_probe()
1325 mt9m111->current_mode = &mt9m111_mode_data[MT9M111_MODE_SXGA_15FPS]; in mt9m111_probe()
1326 mt9m111->frame_interval.numerator = 1; in mt9m111_probe()
1327 mt9m111->frame_interval.denominator = mt9m111->current_mode->max_fps; in mt9m111_probe()
1330 mt9m111->rect.left = MT9M111_MIN_DARK_COLS; in mt9m111_probe()
1331 mt9m111->rect.top = MT9M111_MIN_DARK_ROWS; in mt9m111_probe()
1332 mt9m111->rect.width = MT9M111_MAX_WIDTH; in mt9m111_probe()
1333 mt9m111->rect.height = MT9M111_MAX_HEIGHT; in mt9m111_probe()
1334 mt9m111->width = mt9m111->rect.width; in mt9m111_probe()
1335 mt9m111->height = mt9m111->rect.height; in mt9m111_probe()
1336 mt9m111->fmt = &mt9m111_colour_fmts[0]; in mt9m111_probe()
1337 mt9m111->lastpage = -1; in mt9m111_probe()
1338 mutex_init(&mt9m111->power_lock); in mt9m111_probe()
1344 mt9m111->subdev.dev = &client->dev; in mt9m111_probe()
1345 ret = v4l2_async_register_subdev(&mt9m111->subdev); in mt9m111_probe()
1353 media_entity_cleanup(&mt9m111->subdev.entity); in mt9m111_probe()
1356 v4l2_ctrl_handler_free(&mt9m111->hdl); in mt9m111_probe()
1358 v4l2_clk_put(mt9m111->clk); in mt9m111_probe()
1365 struct mt9m111 *mt9m111 = to_mt9m111(client); in mt9m111_remove() local
1367 v4l2_async_unregister_subdev(&mt9m111->subdev); in mt9m111_remove()
1368 media_entity_cleanup(&mt9m111->subdev.entity); in mt9m111_remove()
1369 v4l2_clk_put(mt9m111->clk); in mt9m111_remove()
1370 v4l2_ctrl_handler_free(&mt9m111->hdl); in mt9m111_remove()