Lines Matching defs:mt9m111

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