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