Lines Matching refs:mt9t001
21 #include <media/i2c/mt9t001.h>
115 struct mt9t001 {
135 static inline struct mt9t001 *to_mt9t001(struct v4l2_subdev *sd)
137 return container_of(sd, struct mt9t001, subdev);
150 static int mt9t001_set_output_control(struct mt9t001 *mt9t001, u16 clear,
153 struct i2c_client *client = v4l2_get_subdevdata(&mt9t001->subdev);
154 u16 value = (mt9t001->output_control & ~clear) | set;
157 if (value == mt9t001->output_control)
164 mt9t001->output_control = value;
168 static int mt9t001_reset(struct mt9t001 *mt9t001)
170 struct i2c_client *client = v4l2_get_subdevdata(&mt9t001->subdev);
182 mt9t001->output_control = MT9T001_OUTPUT_CONTROL_DEF;
184 return mt9t001_set_output_control(mt9t001,
189 static int mt9t001_power_on(struct mt9t001 *mt9t001)
194 ret = regulator_bulk_enable(ARRAY_SIZE(mt9t001->regulators),
195 mt9t001->regulators);
200 ret = clk_prepare_enable(mt9t001->clk);
202 regulator_bulk_disable(ARRAY_SIZE(mt9t001->regulators),
203 mt9t001->regulators);
208 static void mt9t001_power_off(struct mt9t001 *mt9t001)
210 regulator_bulk_disable(ARRAY_SIZE(mt9t001->regulators),
211 mt9t001->regulators);
213 clk_disable_unprepare(mt9t001->clk);
216 static int __mt9t001_set_power(struct mt9t001 *mt9t001, bool on)
218 struct i2c_client *client = v4l2_get_subdevdata(&mt9t001->subdev);
222 mt9t001_power_off(mt9t001);
226 ret = mt9t001_power_on(mt9t001);
230 ret = mt9t001_reset(mt9t001);
236 ret = v4l2_ctrl_handler_setup(&mt9t001->ctrls);
245 mt9t001_power_off(mt9t001);
255 __mt9t001_get_pad_format(struct mt9t001 *mt9t001, struct v4l2_subdev_pad_config *cfg,
260 return v4l2_subdev_get_try_format(&mt9t001->subdev, cfg, pad);
262 return &mt9t001->format;
269 __mt9t001_get_pad_crop(struct mt9t001 *mt9t001, struct v4l2_subdev_pad_config *cfg,
274 return v4l2_subdev_get_try_crop(&mt9t001->subdev, cfg, pad);
276 return &mt9t001->crop;
287 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
288 struct v4l2_mbus_framefmt *format = &mt9t001->format;
289 struct v4l2_rect *crop = &mt9t001->crop;
295 return mt9t001_set_output_control(mt9t001, mode, 0);
334 return mt9t001_set_output_control(mt9t001, 0, mode);
367 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
369 format->format = *__mt9t001_get_pad_format(mt9t001, cfg, format->pad,
378 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
386 __crop = __mt9t001_get_pad_crop(mt9t001, cfg, format->pad,
402 __format = __mt9t001_get_pad_format(mt9t001, cfg, format->pad,
416 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
421 sel->r = *__mt9t001_get_pad_crop(mt9t001, cfg, sel->pad, sel->which);
429 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
458 __crop = __mt9t001_get_pad_crop(mt9t001, cfg, sel->pad, sel->which);
464 __format = __mt9t001_get_pad_format(mt9t001, cfg, sel->pad,
518 static int mt9t001_ctrl_freeze(struct mt9t001 *mt9t001, bool freeze)
520 return mt9t001_set_output_control(mt9t001,
532 struct mt9t001 *mt9t001 =
533 container_of(ctrl->handler, struct mt9t001, ctrls);
534 struct i2c_client *client = v4l2_get_subdevdata(&mt9t001->subdev);
550 struct v4l2_ctrl *gain = mt9t001->gains[i];
557 ret = mt9t001_ctrl_freeze(mt9t001, true);
564 struct v4l2_ctrl *gain = mt9t001->gains[i];
572 mt9t001_ctrl_freeze(mt9t001, false);
579 ret = mt9t001_ctrl_freeze(mt9t001, false);
596 return mt9t001_set_output_control(mt9t001,
610 mt9t001->black_level = value;
631 mt9t001->black_level);
740 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
743 mutex_lock(&mt9t001->power_lock);
748 if (mt9t001->power_count == !on) {
749 ret = __mt9t001_set_power(mt9t001, !!on);
755 mt9t001->power_count += on ? 1 : -1;
756 WARN_ON(mt9t001->power_count < 0);
759 mutex_unlock(&mt9t001->power_lock);
770 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
774 ret = mt9t001_power_on(mt9t001);
782 mt9t001_power_off(mt9t001);
855 struct mt9t001 *mt9t001;
871 mt9t001 = devm_kzalloc(&client->dev, sizeof(*mt9t001), GFP_KERNEL);
872 if (!mt9t001)
875 mutex_init(&mt9t001->power_lock);
876 mt9t001->output_control = MT9T001_OUTPUT_CONTROL_DEF;
878 mt9t001->regulators[0].supply = "vdd";
879 mt9t001->regulators[1].supply = "vaa";
881 ret = devm_regulator_bulk_get(&client->dev, 2, mt9t001->regulators);
887 mt9t001->clk = devm_clk_get(&client->dev, NULL);
888 if (IS_ERR(mt9t001->clk)) {
890 return PTR_ERR(mt9t001->clk);
893 v4l2_ctrl_handler_init(&mt9t001->ctrls, ARRAY_SIZE(mt9t001_ctrls) +
896 v4l2_ctrl_new_std(&mt9t001->ctrls, &mt9t001_ctrl_ops,
900 v4l2_ctrl_new_std(&mt9t001->ctrls, &mt9t001_ctrl_ops,
902 v4l2_ctrl_new_std(&mt9t001->ctrls, &mt9t001_ctrl_ops,
905 v4l2_ctrl_new_std_menu_items(&mt9t001->ctrls, &mt9t001_ctrl_ops,
911 v4l2_ctrl_new_custom(&mt9t001->ctrls, &mt9t001_ctrls[i], NULL);
914 mt9t001->gains[i] = v4l2_ctrl_new_custom(&mt9t001->ctrls,
917 v4l2_ctrl_cluster(ARRAY_SIZE(mt9t001_gains), mt9t001->gains);
919 mt9t001->subdev.ctrl_handler = &mt9t001->ctrls;
921 if (mt9t001->ctrls.error) {
923 __func__, mt9t001->ctrls.error);
928 mt9t001->crop.left = MT9T001_COLUMN_START_DEF;
929 mt9t001->crop.top = MT9T001_ROW_START_DEF;
930 mt9t001->crop.width = MT9T001_WINDOW_WIDTH_DEF + 1;
931 mt9t001->crop.height = MT9T001_WINDOW_HEIGHT_DEF + 1;
933 mt9t001->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
934 mt9t001->format.width = MT9T001_WINDOW_WIDTH_DEF + 1;
935 mt9t001->format.height = MT9T001_WINDOW_HEIGHT_DEF + 1;
936 mt9t001->format.field = V4L2_FIELD_NONE;
937 mt9t001->format.colorspace = V4L2_COLORSPACE_SRGB;
939 v4l2_i2c_subdev_init(&mt9t001->subdev, client, &mt9t001_subdev_ops);
940 mt9t001->subdev.internal_ops = &mt9t001_subdev_internal_ops;
941 mt9t001->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
943 mt9t001->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR;
944 mt9t001->pad.flags = MEDIA_PAD_FL_SOURCE;
945 ret = media_entity_pads_init(&mt9t001->subdev.entity, 1, &mt9t001->pad);
949 v4l2_ctrl_handler_free(&mt9t001->ctrls);
950 media_entity_cleanup(&mt9t001->subdev.entity);
959 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
961 v4l2_ctrl_handler_free(&mt9t001->ctrls);
968 { "mt9t001", 0 },
975 .name = "mt9t001",