mt9p031 146 drivers/media/i2c/mt9p031.c static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd) mt9p031 148 drivers/media/i2c/mt9p031.c return container_of(sd, struct mt9p031, subdev); mt9p031 161 drivers/media/i2c/mt9p031.c static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear, mt9p031 164 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 165 drivers/media/i2c/mt9p031.c u16 value = (mt9p031->output_control & ~clear) | set; mt9p031 172 drivers/media/i2c/mt9p031.c mt9p031->output_control = value; mt9p031 176 drivers/media/i2c/mt9p031.c static int mt9p031_set_mode2(struct mt9p031 *mt9p031, u16 clear, u16 set) mt9p031 178 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 179 drivers/media/i2c/mt9p031.c u16 value = (mt9p031->mode2 & ~clear) | set; mt9p031 186 drivers/media/i2c/mt9p031.c mt9p031->mode2 = value; mt9p031 190 drivers/media/i2c/mt9p031.c static int mt9p031_reset(struct mt9p031 *mt9p031) mt9p031 192 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 204 drivers/media/i2c/mt9p031.c MT9P031_PIXEL_CLOCK_DIVIDE(mt9p031->clk_div)); mt9p031 208 drivers/media/i2c/mt9p031.c return mt9p031_set_output_control(mt9p031, MT9P031_OUTPUT_CONTROL_CEN, mt9p031 212 drivers/media/i2c/mt9p031.c static int mt9p031_clk_setup(struct mt9p031 *mt9p031) mt9p031 230 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 231 drivers/media/i2c/mt9p031.c struct mt9p031_platform_data *pdata = mt9p031->pdata; mt9p031 234 drivers/media/i2c/mt9p031.c mt9p031->clk = devm_clk_get(&client->dev, NULL); mt9p031 235 drivers/media/i2c/mt9p031.c if (IS_ERR(mt9p031->clk)) mt9p031 236 drivers/media/i2c/mt9p031.c return PTR_ERR(mt9p031->clk); mt9p031 238 drivers/media/i2c/mt9p031.c ret = clk_set_rate(mt9p031->clk, pdata->ext_freq); mt9p031 251 drivers/media/i2c/mt9p031.c mt9p031->clk_div = min_t(unsigned int, div, 64); mt9p031 252 drivers/media/i2c/mt9p031.c mt9p031->use_pll = false; mt9p031 257 drivers/media/i2c/mt9p031.c mt9p031->pll.ext_clock = pdata->ext_freq; mt9p031 258 drivers/media/i2c/mt9p031.c mt9p031->pll.pix_clock = pdata->target_freq; mt9p031 259 drivers/media/i2c/mt9p031.c mt9p031->use_pll = true; mt9p031 261 drivers/media/i2c/mt9p031.c return aptina_pll_calculate(&client->dev, &limits, &mt9p031->pll); mt9p031 264 drivers/media/i2c/mt9p031.c static int mt9p031_pll_enable(struct mt9p031 *mt9p031) mt9p031 266 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 269 drivers/media/i2c/mt9p031.c if (!mt9p031->use_pll) mt9p031 278 drivers/media/i2c/mt9p031.c (mt9p031->pll.m << 8) | (mt9p031->pll.n - 1)); mt9p031 282 drivers/media/i2c/mt9p031.c ret = mt9p031_write(client, MT9P031_PLL_CONFIG_2, mt9p031->pll.p1 - 1); mt9p031 293 drivers/media/i2c/mt9p031.c static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031) mt9p031 295 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 297 drivers/media/i2c/mt9p031.c if (!mt9p031->use_pll) mt9p031 304 drivers/media/i2c/mt9p031.c static int mt9p031_power_on(struct mt9p031 *mt9p031) mt9p031 309 drivers/media/i2c/mt9p031.c if (mt9p031->reset) { mt9p031 310 drivers/media/i2c/mt9p031.c gpiod_set_value(mt9p031->reset, 1); mt9p031 315 drivers/media/i2c/mt9p031.c ret = regulator_bulk_enable(ARRAY_SIZE(mt9p031->regulators), mt9p031 316 drivers/media/i2c/mt9p031.c mt9p031->regulators); mt9p031 321 drivers/media/i2c/mt9p031.c if (mt9p031->clk) { mt9p031 322 drivers/media/i2c/mt9p031.c ret = clk_prepare_enable(mt9p031->clk); mt9p031 324 drivers/media/i2c/mt9p031.c regulator_bulk_disable(ARRAY_SIZE(mt9p031->regulators), mt9p031 325 drivers/media/i2c/mt9p031.c mt9p031->regulators); mt9p031 331 drivers/media/i2c/mt9p031.c if (mt9p031->reset) { mt9p031 332 drivers/media/i2c/mt9p031.c gpiod_set_value(mt9p031->reset, 0); mt9p031 339 drivers/media/i2c/mt9p031.c static void mt9p031_power_off(struct mt9p031 *mt9p031) mt9p031 341 drivers/media/i2c/mt9p031.c if (mt9p031->reset) { mt9p031 342 drivers/media/i2c/mt9p031.c gpiod_set_value(mt9p031->reset, 1); mt9p031 346 drivers/media/i2c/mt9p031.c regulator_bulk_disable(ARRAY_SIZE(mt9p031->regulators), mt9p031 347 drivers/media/i2c/mt9p031.c mt9p031->regulators); mt9p031 349 drivers/media/i2c/mt9p031.c if (mt9p031->clk) mt9p031 350 drivers/media/i2c/mt9p031.c clk_disable_unprepare(mt9p031->clk); mt9p031 353 drivers/media/i2c/mt9p031.c static int __mt9p031_set_power(struct mt9p031 *mt9p031, bool on) mt9p031 355 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 359 drivers/media/i2c/mt9p031.c mt9p031_power_off(mt9p031); mt9p031 363 drivers/media/i2c/mt9p031.c ret = mt9p031_power_on(mt9p031); mt9p031 367 drivers/media/i2c/mt9p031.c ret = mt9p031_reset(mt9p031); mt9p031 373 drivers/media/i2c/mt9p031.c return v4l2_ctrl_handler_setup(&mt9p031->ctrls); mt9p031 380 drivers/media/i2c/mt9p031.c static int mt9p031_set_params(struct mt9p031 *mt9p031) mt9p031 382 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 383 drivers/media/i2c/mt9p031.c struct v4l2_mbus_framefmt *format = &mt9p031->format; mt9p031 384 drivers/media/i2c/mt9p031.c const struct v4l2_rect *crop = &mt9p031->crop; mt9p031 447 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 452 drivers/media/i2c/mt9p031.c ret = mt9p031_set_output_control(mt9p031, mt9p031 457 drivers/media/i2c/mt9p031.c return mt9p031_pll_disable(mt9p031); mt9p031 460 drivers/media/i2c/mt9p031.c ret = mt9p031_set_params(mt9p031); mt9p031 465 drivers/media/i2c/mt9p031.c ret = mt9p031_set_output_control(mt9p031, 0, mt9p031 470 drivers/media/i2c/mt9p031.c return mt9p031_pll_enable(mt9p031); mt9p031 477 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 482 drivers/media/i2c/mt9p031.c code->code = mt9p031->format.code; mt9p031 490 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 492 drivers/media/i2c/mt9p031.c if (fse->index >= 8 || fse->code != mt9p031->format.code) mt9p031 505 drivers/media/i2c/mt9p031.c __mt9p031_get_pad_format(struct mt9p031 *mt9p031, struct v4l2_subdev_pad_config *cfg, mt9p031 510 drivers/media/i2c/mt9p031.c return v4l2_subdev_get_try_format(&mt9p031->subdev, cfg, pad); mt9p031 512 drivers/media/i2c/mt9p031.c return &mt9p031->format; mt9p031 519 drivers/media/i2c/mt9p031.c __mt9p031_get_pad_crop(struct mt9p031 *mt9p031, struct v4l2_subdev_pad_config *cfg, mt9p031 524 drivers/media/i2c/mt9p031.c return v4l2_subdev_get_try_crop(&mt9p031->subdev, cfg, pad); mt9p031 526 drivers/media/i2c/mt9p031.c return &mt9p031->crop; mt9p031 536 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 538 drivers/media/i2c/mt9p031.c fmt->format = *__mt9p031_get_pad_format(mt9p031, cfg, fmt->pad, mt9p031 547 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 555 drivers/media/i2c/mt9p031.c __crop = __mt9p031_get_pad_crop(mt9p031, cfg, format->pad, mt9p031 571 drivers/media/i2c/mt9p031.c __format = __mt9p031_get_pad_format(mt9p031, cfg, format->pad, mt9p031 585 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 590 drivers/media/i2c/mt9p031.c sel->r = *__mt9p031_get_pad_crop(mt9p031, cfg, sel->pad, sel->which); mt9p031 598 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 625 drivers/media/i2c/mt9p031.c __crop = __mt9p031_get_pad_crop(mt9p031, cfg, sel->pad, sel->which); mt9p031 631 drivers/media/i2c/mt9p031.c __format = __mt9p031_get_pad_format(mt9p031, cfg, sel->pad, mt9p031 652 drivers/media/i2c/mt9p031.c static int mt9p031_restore_blc(struct mt9p031 *mt9p031) mt9p031 654 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 657 drivers/media/i2c/mt9p031.c if (mt9p031->blc_auto->cur.val != 0) { mt9p031 658 drivers/media/i2c/mt9p031.c ret = mt9p031_set_mode2(mt9p031, 0, mt9p031 664 drivers/media/i2c/mt9p031.c if (mt9p031->blc_offset->cur.val != 0) { mt9p031 666 drivers/media/i2c/mt9p031.c mt9p031->blc_offset->cur.val); mt9p031 676 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = mt9p031 677 drivers/media/i2c/mt9p031.c container_of(ctrl->handler, struct mt9p031, ctrls); mt9p031 678 drivers/media/i2c/mt9p031.c struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev); mt9p031 724 drivers/media/i2c/mt9p031.c return mt9p031_set_mode2(mt9p031, mt9p031 727 drivers/media/i2c/mt9p031.c return mt9p031_set_mode2(mt9p031, mt9p031 732 drivers/media/i2c/mt9p031.c return mt9p031_set_mode2(mt9p031, mt9p031 735 drivers/media/i2c/mt9p031.c return mt9p031_set_mode2(mt9p031, mt9p031 744 drivers/media/i2c/mt9p031.c v4l2_ctrl_activate(mt9p031->blc_auto, ctrl->val == 0); mt9p031 745 drivers/media/i2c/mt9p031.c v4l2_ctrl_activate(mt9p031->blc_offset, ctrl->val == 0); mt9p031 749 drivers/media/i2c/mt9p031.c ret = mt9p031_restore_blc(mt9p031); mt9p031 768 drivers/media/i2c/mt9p031.c ret = mt9p031_set_mode2(mt9p031, MT9P031_READ_MODE_2_ROW_BLC, mt9p031 782 drivers/media/i2c/mt9p031.c ret = mt9p031_set_mode2(mt9p031, mt9p031 884 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 887 drivers/media/i2c/mt9p031.c mutex_lock(&mt9p031->power_lock); mt9p031 892 drivers/media/i2c/mt9p031.c if (mt9p031->power_count == !on) { mt9p031 893 drivers/media/i2c/mt9p031.c ret = __mt9p031_set_power(mt9p031, !!on); mt9p031 899 drivers/media/i2c/mt9p031.c mt9p031->power_count += on ? 1 : -1; mt9p031 900 drivers/media/i2c/mt9p031.c WARN_ON(mt9p031->power_count < 0); mt9p031 903 drivers/media/i2c/mt9p031.c mutex_unlock(&mt9p031->power_lock); mt9p031 914 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 918 drivers/media/i2c/mt9p031.c ret = mt9p031_power_on(mt9p031); mt9p031 926 drivers/media/i2c/mt9p031.c mt9p031_power_off(mt9p031); mt9p031 942 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 954 drivers/media/i2c/mt9p031.c if (mt9p031->model == MT9P031_MODEL_MONOCHROME) mt9p031 1035 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031; mt9p031 1050 drivers/media/i2c/mt9p031.c mt9p031 = devm_kzalloc(&client->dev, sizeof(*mt9p031), GFP_KERNEL); mt9p031 1051 drivers/media/i2c/mt9p031.c if (mt9p031 == NULL) mt9p031 1054 drivers/media/i2c/mt9p031.c mt9p031->pdata = pdata; mt9p031 1055 drivers/media/i2c/mt9p031.c mt9p031->output_control = MT9P031_OUTPUT_CONTROL_DEF; mt9p031 1056 drivers/media/i2c/mt9p031.c mt9p031->mode2 = MT9P031_READ_MODE_2_ROW_BLC; mt9p031 1057 drivers/media/i2c/mt9p031.c mt9p031->model = did->driver_data; mt9p031 1059 drivers/media/i2c/mt9p031.c mt9p031->regulators[0].supply = "vdd"; mt9p031 1060 drivers/media/i2c/mt9p031.c mt9p031->regulators[1].supply = "vdd_io"; mt9p031 1061 drivers/media/i2c/mt9p031.c mt9p031->regulators[2].supply = "vaa"; mt9p031 1063 drivers/media/i2c/mt9p031.c ret = devm_regulator_bulk_get(&client->dev, 3, mt9p031->regulators); mt9p031 1069 drivers/media/i2c/mt9p031.c mutex_init(&mt9p031->power_lock); mt9p031 1071 drivers/media/i2c/mt9p031.c v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6); mt9p031 1073 drivers/media/i2c/mt9p031.c v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops, mt9p031 1077 drivers/media/i2c/mt9p031.c v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops, mt9p031 1080 drivers/media/i2c/mt9p031.c v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops, mt9p031 1082 drivers/media/i2c/mt9p031.c v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops, mt9p031 1084 drivers/media/i2c/mt9p031.c v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops, mt9p031 1087 drivers/media/i2c/mt9p031.c v4l2_ctrl_new_std_menu_items(&mt9p031->ctrls, &mt9p031_ctrl_ops, mt9p031 1093 drivers/media/i2c/mt9p031.c v4l2_ctrl_new_custom(&mt9p031->ctrls, &mt9p031_ctrls[i], NULL); mt9p031 1095 drivers/media/i2c/mt9p031.c mt9p031->subdev.ctrl_handler = &mt9p031->ctrls; mt9p031 1097 drivers/media/i2c/mt9p031.c if (mt9p031->ctrls.error) { mt9p031 1099 drivers/media/i2c/mt9p031.c __func__, mt9p031->ctrls.error); mt9p031 1100 drivers/media/i2c/mt9p031.c ret = mt9p031->ctrls.error; mt9p031 1104 drivers/media/i2c/mt9p031.c mt9p031->blc_auto = v4l2_ctrl_find(&mt9p031->ctrls, V4L2_CID_BLC_AUTO); mt9p031 1105 drivers/media/i2c/mt9p031.c mt9p031->blc_offset = v4l2_ctrl_find(&mt9p031->ctrls, mt9p031 1108 drivers/media/i2c/mt9p031.c v4l2_i2c_subdev_init(&mt9p031->subdev, client, &mt9p031_subdev_ops); mt9p031 1109 drivers/media/i2c/mt9p031.c mt9p031->subdev.internal_ops = &mt9p031_subdev_internal_ops; mt9p031 1111 drivers/media/i2c/mt9p031.c mt9p031->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; mt9p031 1112 drivers/media/i2c/mt9p031.c mt9p031->pad.flags = MEDIA_PAD_FL_SOURCE; mt9p031 1113 drivers/media/i2c/mt9p031.c ret = media_entity_pads_init(&mt9p031->subdev.entity, 1, &mt9p031->pad); mt9p031 1117 drivers/media/i2c/mt9p031.c mt9p031->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; mt9p031 1119 drivers/media/i2c/mt9p031.c mt9p031->crop.width = MT9P031_WINDOW_WIDTH_DEF; mt9p031 1120 drivers/media/i2c/mt9p031.c mt9p031->crop.height = MT9P031_WINDOW_HEIGHT_DEF; mt9p031 1121 drivers/media/i2c/mt9p031.c mt9p031->crop.left = MT9P031_COLUMN_START_DEF; mt9p031 1122 drivers/media/i2c/mt9p031.c mt9p031->crop.top = MT9P031_ROW_START_DEF; mt9p031 1124 drivers/media/i2c/mt9p031.c if (mt9p031->model == MT9P031_MODEL_MONOCHROME) mt9p031 1125 drivers/media/i2c/mt9p031.c mt9p031->format.code = MEDIA_BUS_FMT_Y12_1X12; mt9p031 1127 drivers/media/i2c/mt9p031.c mt9p031->format.code = MEDIA_BUS_FMT_SGRBG12_1X12; mt9p031 1129 drivers/media/i2c/mt9p031.c mt9p031->format.width = MT9P031_WINDOW_WIDTH_DEF; mt9p031 1130 drivers/media/i2c/mt9p031.c mt9p031->format.height = MT9P031_WINDOW_HEIGHT_DEF; mt9p031 1131 drivers/media/i2c/mt9p031.c mt9p031->format.field = V4L2_FIELD_NONE; mt9p031 1132 drivers/media/i2c/mt9p031.c mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB; mt9p031 1134 drivers/media/i2c/mt9p031.c mt9p031->reset = devm_gpiod_get_optional(&client->dev, "reset", mt9p031 1137 drivers/media/i2c/mt9p031.c ret = mt9p031_clk_setup(mt9p031); mt9p031 1141 drivers/media/i2c/mt9p031.c ret = v4l2_async_register_subdev(&mt9p031->subdev); mt9p031 1145 drivers/media/i2c/mt9p031.c v4l2_ctrl_handler_free(&mt9p031->ctrls); mt9p031 1146 drivers/media/i2c/mt9p031.c media_entity_cleanup(&mt9p031->subdev.entity); mt9p031 1147 drivers/media/i2c/mt9p031.c mutex_destroy(&mt9p031->power_lock); mt9p031 1156 drivers/media/i2c/mt9p031.c struct mt9p031 *mt9p031 = to_mt9p031(subdev); mt9p031 1158 drivers/media/i2c/mt9p031.c v4l2_ctrl_handler_free(&mt9p031->ctrls); mt9p031 1161 drivers/media/i2c/mt9p031.c mutex_destroy(&mt9p031->power_lock);