Lines Matching refs:mt9v111
278 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(sd); in __mt9v111_addr_space_select() local
282 if (mt9v111->addr_space == addr_space) in __mt9v111_addr_space_select()
297 mt9v111->addr_space = addr_space; in __mt9v111_addr_space_select()
363 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(sd); in __mt9v111_power_on() local
366 ret = clk_prepare_enable(mt9v111->clk); in __mt9v111_power_on()
370 clk_set_rate(mt9v111->clk, mt9v111->sysclk); in __mt9v111_power_on()
372 gpiod_set_value(mt9v111->standby, 0); in __mt9v111_power_on()
375 gpiod_set_value(mt9v111->oe, 1); in __mt9v111_power_on()
383 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(sd); in __mt9v111_power_off() local
385 gpiod_set_value(mt9v111->oe, 0); in __mt9v111_power_off()
388 gpiod_set_value(mt9v111->standby, 1); in __mt9v111_power_off()
391 clk_disable_unprepare(mt9v111->clk); in __mt9v111_power_off()
396 static int __mt9v111_hw_reset(struct mt9v111_dev *mt9v111) in __mt9v111_hw_reset() argument
398 if (!mt9v111->reset) in __mt9v111_hw_reset()
401 gpiod_set_value(mt9v111->reset, 1); in __mt9v111_hw_reset()
404 gpiod_set_value(mt9v111->reset, 0); in __mt9v111_hw_reset()
410 static int __mt9v111_sw_reset(struct mt9v111_dev *mt9v111) in __mt9v111_sw_reset() argument
412 struct i2c_client *c = mt9v111->client; in __mt9v111_sw_reset()
448 static int mt9v111_calc_frame_rate(struct mt9v111_dev *mt9v111, in mt9v111_calc_frame_rate() argument
493 pclk = DIV_ROUND_CLOSEST(mt9v111->sysclk, 2); in mt9v111_calc_frame_rate()
520 ret = v4l2_ctrl_s_ctrl_int64(mt9v111->hblank, hb); in mt9v111_calc_frame_rate()
524 ret = v4l2_ctrl_s_ctrl_int64(mt9v111->vblank, vb); in mt9v111_calc_frame_rate()
534 static int mt9v111_hw_config(struct mt9v111_dev *mt9v111) in mt9v111_hw_config() argument
536 struct i2c_client *c = mt9v111->client; in mt9v111_hw_config()
541 ret = __mt9v111_hw_reset(mt9v111); in mt9v111_hw_config()
543 ret = __mt9v111_sw_reset(mt9v111); in mt9v111_hw_config()
548 ret = mt9v111->sysclk < DIV_ROUND_CLOSEST(MT9V111_MAX_CLKIN, 2) ? in mt9v111_hw_config()
564 switch (mt9v111->fmt.code) { in mt9v111_hw_config()
620 mt9v111->fmt.width); in mt9v111_hw_config()
625 mt9v111->fmt.height); in mt9v111_hw_config()
630 ret = v4l2_ctrl_handler_setup(&mt9v111->ctrls); in mt9v111_hw_config()
648 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(sd); in mt9v111_s_power() local
652 mutex_lock(&mt9v111->pwr_mutex); in mt9v111_s_power()
658 pwr_count = mt9v111->pwr_count; in mt9v111_s_power()
665 mt9v111->pwr_count = pwr_count; in mt9v111_s_power()
667 mutex_unlock(&mt9v111->pwr_mutex); in mt9v111_s_power()
677 mt9v111->pwr_count = pwr_count; in mt9v111_s_power()
679 mutex_unlock(&mt9v111->pwr_mutex); in mt9v111_s_power()
686 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(subdev); in mt9v111_s_stream() local
689 mutex_lock(&mt9v111->stream_mutex); in mt9v111_s_stream()
691 if (mt9v111->streaming == enable) { in mt9v111_s_stream()
692 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_s_stream()
700 if (enable && mt9v111->pending) { in mt9v111_s_stream()
701 ret = mt9v111_hw_config(mt9v111); in mt9v111_s_stream()
710 mt9v111->pending = false; in mt9v111_s_stream()
713 mt9v111->streaming = enable ? true : false; in mt9v111_s_stream()
714 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_s_stream()
719 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_s_stream()
727 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(sd); in mt9v111_s_frame_interval() local
737 mutex_lock(&mt9v111->stream_mutex); in mt9v111_s_frame_interval()
739 if (mt9v111->streaming) { in mt9v111_s_frame_interval()
740 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_s_frame_interval()
744 if (mt9v111->fps == fps) { in mt9v111_s_frame_interval()
745 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_s_frame_interval()
750 if (mt9v111->fmt.width < QVGA_WIDTH && in mt9v111_s_frame_interval()
751 mt9v111->fmt.height < QVGA_HEIGHT) in mt9v111_s_frame_interval()
753 else if (mt9v111->fmt.width < CIF_WIDTH && in mt9v111_s_frame_interval()
754 mt9v111->fmt.height < CIF_HEIGHT) in mt9v111_s_frame_interval()
757 max_fps = mt9v111->sysclk < in mt9v111_s_frame_interval()
762 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_s_frame_interval()
766 mt9v111_calc_frame_rate(mt9v111, tpf); in mt9v111_s_frame_interval()
768 mt9v111->fps = fps; in mt9v111_s_frame_interval()
769 mt9v111->pending = true; in mt9v111_s_frame_interval()
771 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_s_frame_interval()
779 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(sd); in mt9v111_g_frame_interval() local
782 mutex_lock(&mt9v111->stream_mutex); in mt9v111_g_frame_interval()
785 tpf->denominator = mt9v111->fps; in mt9v111_g_frame_interval()
787 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_g_frame_interval()
793 struct mt9v111_dev *mt9v111, in __mt9v111_get_pad_format() argument
801 return v4l2_subdev_get_try_format(&mt9v111->sd, sd_state, pad); in __mt9v111_get_pad_format()
806 return &mt9v111->fmt; in __mt9v111_get_pad_format()
866 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(subdev); in mt9v111_get_format() local
871 mutex_lock(&mt9v111->stream_mutex); in mt9v111_get_format()
872 format->format = *__mt9v111_get_pad_format(mt9v111, sd_state, in mt9v111_get_format()
875 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_get_format()
884 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(subdev); in mt9v111_set_format() local
891 mutex_lock(&mt9v111->stream_mutex); in mt9v111_set_format()
892 if (mt9v111->streaming) { in mt9v111_set_format()
893 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_set_format()
898 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_set_format()
929 __fmt = __mt9v111_get_pad_format(mt9v111, sd_state, format->pad, in mt9v111_set_format()
944 mt9v111->pending = true; in mt9v111_set_format()
946 dev_dbg(mt9v111->dev, "%s: mbus_code: %x - (%ux%u)\n", in mt9v111_set_format()
952 mutex_unlock(&mt9v111->stream_mutex); in mt9v111_set_format()
999 struct mt9v111_dev *mt9v111 = container_of(ctrl->handler, in mt9v111_s_ctrl() local
1004 mutex_lock(&mt9v111->pwr_mutex); in mt9v111_s_ctrl()
1009 if (!mt9v111->pwr_count) { in mt9v111_s_ctrl()
1010 mt9v111->pending = true; in mt9v111_s_ctrl()
1011 mutex_unlock(&mt9v111->pwr_mutex); in mt9v111_s_ctrl()
1014 mutex_unlock(&mt9v111->pwr_mutex); in mt9v111_s_ctrl()
1023 if (mt9v111->auto_exp->is_new || mt9v111->auto_awb->is_new) { in mt9v111_s_ctrl()
1024 if (mt9v111->auto_exp->val == V4L2_EXPOSURE_MANUAL && in mt9v111_s_ctrl()
1025 mt9v111->auto_awb->val == V4L2_WHITE_BALANCE_MANUAL) in mt9v111_s_ctrl()
1026 ret = mt9v111_update(mt9v111->client, MT9V111_R01_IFP, in mt9v111_s_ctrl()
1031 ret = mt9v111_update(mt9v111->client, MT9V111_R01_IFP, in mt9v111_s_ctrl()
1042 ret = mt9v111_update(mt9v111->client, MT9V111_R01_IFP, in mt9v111_s_ctrl()
1049 ret = mt9v111_update(mt9v111->client, MT9V111_R01_IFP, in mt9v111_s_ctrl()
1056 ret = mt9v111_update(mt9v111->client, MT9V111_R01_CORE, in mt9v111_s_ctrl()
1059 mt9v111->hblank->val); in mt9v111_s_ctrl()
1062 ret = mt9v111_update(mt9v111->client, MT9V111_R01_CORE, in mt9v111_s_ctrl()
1065 mt9v111->vblank->val); in mt9v111_s_ctrl()
1076 static int mt9v111_chip_probe(struct mt9v111_dev *mt9v111) in mt9v111_chip_probe() argument
1081 ret = __mt9v111_power_on(&mt9v111->sd); in mt9v111_chip_probe()
1085 ret = mt9v111_read(mt9v111->client, MT9V111_R01_CORE, in mt9v111_chip_probe()
1092 dev_err(mt9v111->dev, in mt9v111_chip_probe()
1099 dev_dbg(mt9v111->dev, "Chip identified: 0x%2x%2x\n", in mt9v111_chip_probe()
1103 __mt9v111_power_off(&mt9v111->sd); in mt9v111_chip_probe()
1110 struct mt9v111_dev *mt9v111; in mt9v111_probe() local
1114 mt9v111 = devm_kzalloc(&client->dev, sizeof(*mt9v111), GFP_KERNEL); in mt9v111_probe()
1115 if (!mt9v111) in mt9v111_probe()
1118 mt9v111->dev = &client->dev; in mt9v111_probe()
1119 mt9v111->client = client; in mt9v111_probe()
1121 mt9v111->clk = devm_clk_get(&client->dev, NULL); in mt9v111_probe()
1122 if (IS_ERR(mt9v111->clk)) in mt9v111_probe()
1123 return PTR_ERR(mt9v111->clk); in mt9v111_probe()
1125 mt9v111->sysclk = clk_get_rate(mt9v111->clk); in mt9v111_probe()
1126 if (mt9v111->sysclk > MT9V111_MAX_CLKIN) in mt9v111_probe()
1129 mt9v111->oe = devm_gpiod_get_optional(&client->dev, "enable", in mt9v111_probe()
1131 if (IS_ERR(mt9v111->oe)) { in mt9v111_probe()
1133 PTR_ERR(mt9v111->oe)); in mt9v111_probe()
1134 return PTR_ERR(mt9v111->oe); in mt9v111_probe()
1137 mt9v111->standby = devm_gpiod_get_optional(&client->dev, "standby", in mt9v111_probe()
1139 if (IS_ERR(mt9v111->standby)) { in mt9v111_probe()
1141 PTR_ERR(mt9v111->standby)); in mt9v111_probe()
1142 return PTR_ERR(mt9v111->standby); in mt9v111_probe()
1145 mt9v111->reset = devm_gpiod_get_optional(&client->dev, "reset", in mt9v111_probe()
1147 if (IS_ERR(mt9v111->reset)) { in mt9v111_probe()
1149 PTR_ERR(mt9v111->reset)); in mt9v111_probe()
1150 return PTR_ERR(mt9v111->reset); in mt9v111_probe()
1153 mutex_init(&mt9v111->pwr_mutex); in mt9v111_probe()
1154 mutex_init(&mt9v111->stream_mutex); in mt9v111_probe()
1156 v4l2_ctrl_handler_init(&mt9v111->ctrls, 5); in mt9v111_probe()
1158 mt9v111->auto_awb = v4l2_ctrl_new_std(&mt9v111->ctrls, in mt9v111_probe()
1163 mt9v111->auto_exp = v4l2_ctrl_new_std_menu(&mt9v111->ctrls, in mt9v111_probe()
1168 mt9v111->hblank = v4l2_ctrl_new_std(&mt9v111->ctrls, &mt9v111_ctrl_ops, in mt9v111_probe()
1173 mt9v111->vblank = v4l2_ctrl_new_std(&mt9v111->ctrls, &mt9v111_ctrl_ops, in mt9v111_probe()
1180 v4l2_ctrl_new_std(&mt9v111->ctrls, &mt9v111_ctrl_ops, in mt9v111_probe()
1182 DIV_ROUND_CLOSEST(mt9v111->sysclk, 2), 1, in mt9v111_probe()
1183 DIV_ROUND_CLOSEST(mt9v111->sysclk, 2)); in mt9v111_probe()
1185 if (mt9v111->ctrls.error) { in mt9v111_probe()
1186 ret = mt9v111->ctrls.error; in mt9v111_probe()
1189 mt9v111->sd.ctrl_handler = &mt9v111->ctrls; in mt9v111_probe()
1192 mt9v111->fmt = mt9v111_def_fmt; in mt9v111_probe()
1195 mt9v111->fps = 15; in mt9v111_probe()
1197 tpf.denominator = mt9v111->fps; in mt9v111_probe()
1198 mt9v111_calc_frame_rate(mt9v111, &tpf); in mt9v111_probe()
1200 mt9v111->pwr_count = 0; in mt9v111_probe()
1201 mt9v111->addr_space = MT9V111_R01_IFP; in mt9v111_probe()
1202 mt9v111->pending = true; in mt9v111_probe()
1204 v4l2_i2c_subdev_init(&mt9v111->sd, client, &mt9v111_ops); in mt9v111_probe()
1207 mt9v111->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in mt9v111_probe()
1208 mt9v111->sd.entity.ops = &mt9v111_subdev_entity_ops; in mt9v111_probe()
1209 mt9v111->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in mt9v111_probe()
1211 mt9v111->pad.flags = MEDIA_PAD_FL_SOURCE; in mt9v111_probe()
1212 ret = media_entity_pads_init(&mt9v111->sd.entity, 1, &mt9v111->pad); in mt9v111_probe()
1217 ret = mt9v111_chip_probe(mt9v111); in mt9v111_probe()
1221 ret = v4l2_async_register_subdev(&mt9v111->sd); in mt9v111_probe()
1229 media_entity_cleanup(&mt9v111->sd.entity); in mt9v111_probe()
1233 v4l2_ctrl_handler_free(&mt9v111->ctrls); in mt9v111_probe()
1235 mutex_destroy(&mt9v111->pwr_mutex); in mt9v111_probe()
1236 mutex_destroy(&mt9v111->stream_mutex); in mt9v111_probe()
1244 struct mt9v111_dev *mt9v111 = sd_to_mt9v111(sd); in mt9v111_remove() local
1252 v4l2_ctrl_handler_free(&mt9v111->ctrls); in mt9v111_remove()
1254 mutex_destroy(&mt9v111->pwr_mutex); in mt9v111_remove()
1255 mutex_destroy(&mt9v111->stream_mutex); in mt9v111_remove()