Lines Matching full:sensor
3 * Driver for MT9M032 CMOS Image Sensor from Micron
125 * for this sensor.
155 #define to_dev(sensor) \ argument
156 (&((struct i2c_client *)v4l2_get_subdevdata(&(sensor)->subdev))->dev)
168 static u32 mt9m032_row_time(struct mt9m032 *sensor, unsigned int width) in mt9m032_row_time() argument
174 ns = div_u64(1000000000ULL * effective_width, sensor->pix_clock); in mt9m032_row_time()
175 dev_dbg(to_dev(sensor), "MT9M032 line time: %u ns\n", ns); in mt9m032_row_time()
179 static int mt9m032_update_timing(struct mt9m032 *sensor, in mt9m032_update_timing() argument
182 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in mt9m032_update_timing()
183 struct v4l2_rect *crop = &sensor->crop; in mt9m032_update_timing()
189 interval = &sensor->frame_interval; in mt9m032_update_timing()
191 row_time = mt9m032_row_time(sensor, crop->width); in mt9m032_update_timing()
215 static int mt9m032_update_geom_timing(struct mt9m032 *sensor) in mt9m032_update_geom_timing() argument
217 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in mt9m032_update_geom_timing()
221 sensor->crop.width - 1); in mt9m032_update_geom_timing()
224 sensor->crop.height - 1); in mt9m032_update_geom_timing()
227 sensor->crop.left); in mt9m032_update_geom_timing()
230 sensor->crop.top); in mt9m032_update_geom_timing()
232 ret = mt9m032_update_timing(sensor, NULL); in mt9m032_update_geom_timing()
236 static int update_formatter2(struct mt9m032 *sensor, bool streaming) in update_formatter2() argument
238 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in update_formatter2()
249 static int mt9m032_setup_pll(struct mt9m032 *sensor) in mt9m032_setup_pll() argument
267 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in mt9m032_setup_pll()
268 struct mt9m032_platform_data *pdata = sensor->pdata; in mt9m032_setup_pll()
280 sensor->pix_clock = pdata->pix_clock; in mt9m032_setup_pll()
334 * @sensor: pointer to the sensor struct
341 __mt9m032_get_pad_crop(struct mt9m032 *sensor, in __mt9m032_get_pad_crop() argument
347 return v4l2_subdev_get_try_crop(&sensor->subdev, sd_state, 0); in __mt9m032_get_pad_crop()
349 return &sensor->crop; in __mt9m032_get_pad_crop()
357 * @sensor: pointer to the sensor struct
364 __mt9m032_get_pad_format(struct mt9m032 *sensor, in __mt9m032_get_pad_format() argument
370 return v4l2_subdev_get_try_format(&sensor->subdev, sd_state, in __mt9m032_get_pad_format()
373 return &sensor->format; in __mt9m032_get_pad_format()
383 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_get_pad_format() local
385 mutex_lock(&sensor->lock); in mt9m032_get_pad_format()
386 fmt->format = *__mt9m032_get_pad_format(sensor, sd_state, fmt->which); in mt9m032_get_pad_format()
387 mutex_unlock(&sensor->lock); in mt9m032_get_pad_format()
396 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_set_pad_format() local
399 mutex_lock(&sensor->lock); in mt9m032_set_pad_format()
401 if (sensor->streaming && fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in mt9m032_set_pad_format()
407 fmt->format = *__mt9m032_get_pad_format(sensor, sd_state, fmt->which); in mt9m032_set_pad_format()
411 mutex_unlock(&sensor->lock); in mt9m032_set_pad_format()
419 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_get_pad_selection() local
424 mutex_lock(&sensor->lock); in mt9m032_get_pad_selection()
425 sel->r = *__mt9m032_get_pad_crop(sensor, sd_state, sel->which); in mt9m032_get_pad_selection()
426 mutex_unlock(&sensor->lock); in mt9m032_get_pad_selection()
435 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_set_pad_selection() local
444 mutex_lock(&sensor->lock); in mt9m032_set_pad_selection()
446 if (sensor->streaming && sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in mt9m032_set_pad_selection()
468 __crop = __mt9m032_get_pad_crop(sensor, sd_state, sel->which); in mt9m032_set_pad_selection()
474 format = __mt9m032_get_pad_format(sensor, sd_state, in mt9m032_set_pad_selection()
484 ret = mt9m032_update_geom_timing(sensor); in mt9m032_set_pad_selection()
487 mutex_unlock(&sensor->lock); in mt9m032_set_pad_selection()
494 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_get_frame_interval() local
496 mutex_lock(&sensor->lock); in mt9m032_get_frame_interval()
498 fi->interval = sensor->frame_interval; in mt9m032_get_frame_interval()
499 mutex_unlock(&sensor->lock); in mt9m032_get_frame_interval()
507 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_set_frame_interval() local
510 mutex_lock(&sensor->lock); in mt9m032_set_frame_interval()
512 if (sensor->streaming) { in mt9m032_set_frame_interval()
521 ret = mt9m032_update_timing(sensor, &fi->interval); in mt9m032_set_frame_interval()
523 sensor->frame_interval = fi->interval; in mt9m032_set_frame_interval()
526 mutex_unlock(&sensor->lock); in mt9m032_set_frame_interval()
532 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_s_stream() local
535 mutex_lock(&sensor->lock); in mt9m032_s_stream()
536 ret = update_formatter2(sensor, streaming); in mt9m032_s_stream()
538 sensor->streaming = streaming; in mt9m032_s_stream()
539 mutex_unlock(&sensor->lock); in mt9m032_s_stream()
552 struct mt9m032 *sensor = to_mt9m032(sd); in mt9m032_g_register() local
553 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in mt9m032_g_register()
572 struct mt9m032 *sensor = to_mt9m032(sd); in mt9m032_s_register() local
573 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in mt9m032_s_register()
586 static int update_read_mode2(struct mt9m032 *sensor, bool vflip, bool hflip) in update_read_mode2() argument
588 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in update_read_mode2()
597 static int mt9m032_set_gain(struct mt9m032 *sensor, s32 val) in mt9m032_set_gain() argument
599 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in mt9m032_set_gain()
638 struct mt9m032 *sensor = in mt9m032_set_ctrl() local
640 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); in mt9m032_set_ctrl()
645 return mt9m032_set_gain(sensor, ctrl->val); in mt9m032_set_ctrl()
649 return update_read_mode2(sensor, sensor->vflip->val, in mt9m032_set_ctrl()
650 sensor->hflip->val); in mt9m032_set_ctrl()
709 struct mt9m032 *sensor; in mt9m032_probe() local
727 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); in mt9m032_probe()
728 if (sensor == NULL) in mt9m032_probe()
731 mutex_init(&sensor->lock); in mt9m032_probe()
733 sensor->pdata = pdata; in mt9m032_probe()
735 v4l2_i2c_subdev_init(&sensor->subdev, client, &mt9m032_ops); in mt9m032_probe()
736 sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in mt9m032_probe()
749 sensor->frame_interval.numerator = 1; in mt9m032_probe()
750 sensor->frame_interval.denominator = 30; in mt9m032_probe()
752 sensor->crop.left = MT9M032_COLUMN_START_DEF; in mt9m032_probe()
753 sensor->crop.top = MT9M032_ROW_START_DEF; in mt9m032_probe()
754 sensor->crop.width = MT9M032_COLUMN_SIZE_DEF; in mt9m032_probe()
755 sensor->crop.height = MT9M032_ROW_SIZE_DEF; in mt9m032_probe()
757 sensor->format.width = sensor->crop.width; in mt9m032_probe()
758 sensor->format.height = sensor->crop.height; in mt9m032_probe()
759 sensor->format.code = MEDIA_BUS_FMT_Y8_1X8; in mt9m032_probe()
760 sensor->format.field = V4L2_FIELD_NONE; in mt9m032_probe()
761 sensor->format.colorspace = V4L2_COLORSPACE_SRGB; in mt9m032_probe()
763 v4l2_ctrl_handler_init(&sensor->ctrls, 5); in mt9m032_probe()
765 v4l2_ctrl_new_std(&sensor->ctrls, &mt9m032_ctrl_ops, in mt9m032_probe()
768 sensor->hflip = v4l2_ctrl_new_std(&sensor->ctrls, in mt9m032_probe()
771 sensor->vflip = v4l2_ctrl_new_std(&sensor->ctrls, in mt9m032_probe()
775 v4l2_ctrl_new_std(&sensor->ctrls, &mt9m032_ctrl_ops, in mt9m032_probe()
779 v4l2_ctrl_new_std(&sensor->ctrls, &mt9m032_ctrl_ops, in mt9m032_probe()
783 if (sensor->ctrls.error) { in mt9m032_probe()
784 ret = sensor->ctrls.error; in mt9m032_probe()
789 v4l2_ctrl_cluster(2, &sensor->hflip); in mt9m032_probe()
791 sensor->subdev.ctrl_handler = &sensor->ctrls; in mt9m032_probe()
792 sensor->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in mt9m032_probe()
793 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in mt9m032_probe()
794 ret = media_entity_pads_init(&sensor->subdev.entity, 1, &sensor->pad); in mt9m032_probe()
805 ret = mt9m032_setup_pll(sensor); in mt9m032_probe()
810 ret = v4l2_ctrl_handler_setup(&sensor->ctrls); in mt9m032_probe()
815 ret = mt9m032_update_geom_timing(sensor); in mt9m032_probe()
831 if (sensor->pdata->invert_pixclock) { in mt9m032_probe()
846 ret = update_formatter2(sensor, false); in mt9m032_probe()
853 media_entity_cleanup(&sensor->subdev.entity); in mt9m032_probe()
855 v4l2_ctrl_handler_free(&sensor->ctrls); in mt9m032_probe()
857 mutex_destroy(&sensor->lock); in mt9m032_probe()
864 struct mt9m032 *sensor = to_mt9m032(subdev); in mt9m032_remove() local
867 v4l2_ctrl_handler_free(&sensor->ctrls); in mt9m032_remove()
869 mutex_destroy(&sensor->lock); in mt9m032_remove()
891 MODULE_DESCRIPTION("MT9M032 camera sensor driver");