drivers/media/i2c/mt9p031.c
1007
mt9p031_power_off(mt9p031);
drivers/media/i2c/mt9p031.c
1065
static int mt9p031_parse_properties(struct mt9p031 *mt9p031, struct device *dev)
drivers/media/i2c/mt9p031.c
1083
&mt9p031->ext_freq);
drivers/media/i2c/mt9p031.c
1085
&mt9p031->target_freq);
drivers/media/i2c/mt9p031.c
1087
mt9p031->pixclk_pol = !!(endpoint.bus.parallel.flags &
drivers/media/i2c/mt9p031.c
1097
struct mt9p031 *mt9p031;
drivers/media/i2c/mt9p031.c
1107
mt9p031 = devm_kzalloc(&client->dev, sizeof(*mt9p031), GFP_KERNEL);
drivers/media/i2c/mt9p031.c
1108
if (mt9p031 == NULL)
drivers/media/i2c/mt9p031.c
1111
ret = mt9p031_parse_properties(mt9p031, &client->dev);
drivers/media/i2c/mt9p031.c
1115
mt9p031->output_control = MT9P031_OUTPUT_CONTROL_DEF;
drivers/media/i2c/mt9p031.c
1116
mt9p031->mode2 = MT9P031_READ_MODE_2_ROW_BLC;
drivers/media/i2c/mt9p031.c
1118
mt9p031->code = info->code;
drivers/media/i2c/mt9p031.c
1120
mt9p031->regulators[0].supply = "vdd";
drivers/media/i2c/mt9p031.c
1121
mt9p031->regulators[1].supply = "vdd_io";
drivers/media/i2c/mt9p031.c
1122
mt9p031->regulators[2].supply = "vaa";
drivers/media/i2c/mt9p031.c
1124
ret = devm_regulator_bulk_get(&client->dev, 3, mt9p031->regulators);
drivers/media/i2c/mt9p031.c
1130
mutex_init(&mt9p031->power_lock);
drivers/media/i2c/mt9p031.c
1132
v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6);
drivers/media/i2c/mt9p031.c
1134
v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
drivers/media/i2c/mt9p031.c
1138
v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
drivers/media/i2c/mt9p031.c
1141
v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
drivers/media/i2c/mt9p031.c
1143
v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
drivers/media/i2c/mt9p031.c
1145
v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,
drivers/media/i2c/mt9p031.c
1146
V4L2_CID_PIXEL_RATE, mt9p031->target_freq,
drivers/media/i2c/mt9p031.c
1147
mt9p031->target_freq, 1, mt9p031->target_freq);
drivers/media/i2c/mt9p031.c
1148
v4l2_ctrl_new_std_menu_items(&mt9p031->ctrls, &mt9p031_ctrl_ops,
drivers/media/i2c/mt9p031.c
1154
v4l2_ctrl_new_custom(&mt9p031->ctrls, &mt9p031_ctrls[i], NULL);
drivers/media/i2c/mt9p031.c
1156
mt9p031->subdev.ctrl_handler = &mt9p031->ctrls;
drivers/media/i2c/mt9p031.c
1158
if (mt9p031->ctrls.error) {
drivers/media/i2c/mt9p031.c
1160
__func__, mt9p031->ctrls.error);
drivers/media/i2c/mt9p031.c
1161
ret = mt9p031->ctrls.error;
drivers/media/i2c/mt9p031.c
1165
mt9p031->blc_auto = v4l2_ctrl_find(&mt9p031->ctrls, V4L2_CID_BLC_AUTO);
drivers/media/i2c/mt9p031.c
1166
mt9p031->blc_offset = v4l2_ctrl_find(&mt9p031->ctrls,
drivers/media/i2c/mt9p031.c
1169
v4l2_i2c_subdev_init(&mt9p031->subdev, client, &mt9p031_subdev_ops);
drivers/media/i2c/mt9p031.c
1170
mt9p031->subdev.internal_ops = &mt9p031_subdev_internal_ops;
drivers/media/i2c/mt9p031.c
1172
mt9p031->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR;
drivers/media/i2c/mt9p031.c
1173
mt9p031->pad.flags = MEDIA_PAD_FL_SOURCE;
drivers/media/i2c/mt9p031.c
1174
ret = media_entity_pads_init(&mt9p031->subdev.entity, 1, &mt9p031->pad);
drivers/media/i2c/mt9p031.c
1178
mt9p031->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
drivers/media/i2c/mt9p031.c
1180
ret = mt9p031_init_state(&mt9p031->subdev, NULL);
drivers/media/i2c/mt9p031.c
1184
mt9p031->reset = devm_gpiod_get_optional(&client->dev, "reset",
drivers/media/i2c/mt9p031.c
1186
if (IS_ERR(mt9p031->reset)) {
drivers/media/i2c/mt9p031.c
1187
ret = PTR_ERR(mt9p031->reset);
drivers/media/i2c/mt9p031.c
1191
ret = mt9p031_clk_setup(mt9p031);
drivers/media/i2c/mt9p031.c
1195
ret = v4l2_async_register_subdev(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
1199
v4l2_ctrl_handler_free(&mt9p031->ctrls);
drivers/media/i2c/mt9p031.c
1200
media_entity_cleanup(&mt9p031->subdev.entity);
drivers/media/i2c/mt9p031.c
1201
mutex_destroy(&mt9p031->power_lock);
drivers/media/i2c/mt9p031.c
1210
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
1212
v4l2_ctrl_handler_free(&mt9p031->ctrls);
drivers/media/i2c/mt9p031.c
1215
mutex_destroy(&mt9p031->power_lock);
drivers/media/i2c/mt9p031.c
147
static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd)
drivers/media/i2c/mt9p031.c
149
return container_of(sd, struct mt9p031, subdev);
drivers/media/i2c/mt9p031.c
162
static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear,
drivers/media/i2c/mt9p031.c
165
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
166
u16 value = (mt9p031->output_control & ~clear) | set;
drivers/media/i2c/mt9p031.c
173
mt9p031->output_control = value;
drivers/media/i2c/mt9p031.c
177
static int mt9p031_set_mode2(struct mt9p031 *mt9p031, u16 clear, u16 set)
drivers/media/i2c/mt9p031.c
179
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
180
u16 value = (mt9p031->mode2 & ~clear) | set;
drivers/media/i2c/mt9p031.c
187
mt9p031->mode2 = value;
drivers/media/i2c/mt9p031.c
191
static int mt9p031_reset(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
193
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
205
MT9P031_PIXEL_CLOCK_DIVIDE(mt9p031->clk_div));
drivers/media/i2c/mt9p031.c
209
return mt9p031_set_output_control(mt9p031, MT9P031_OUTPUT_CONTROL_CEN,
drivers/media/i2c/mt9p031.c
213
static int mt9p031_clk_setup(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
231
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
235
mt9p031->clk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
drivers/media/i2c/mt9p031.c
236
if (IS_ERR(mt9p031->clk))
drivers/media/i2c/mt9p031.c
237
return dev_err_probe(&client->dev, PTR_ERR(mt9p031->clk),
drivers/media/i2c/mt9p031.c
240
ret = clk_set_rate(mt9p031->clk, mt9p031->ext_freq);
drivers/media/i2c/mt9p031.c
244
ext_freq = clk_get_rate(mt9p031->clk);
drivers/media/i2c/mt9p031.c
252
div = DIV_ROUND_UP(ext_freq, mt9p031->target_freq);
drivers/media/i2c/mt9p031.c
255
mt9p031->clk_div = min_t(unsigned int, div, 64);
drivers/media/i2c/mt9p031.c
256
mt9p031->use_pll = false;
drivers/media/i2c/mt9p031.c
261
mt9p031->pll.ext_clock = ext_freq;
drivers/media/i2c/mt9p031.c
262
mt9p031->pll.pix_clock = mt9p031->target_freq;
drivers/media/i2c/mt9p031.c
263
mt9p031->use_pll = true;
drivers/media/i2c/mt9p031.c
265
return aptina_pll_calculate(&client->dev, &limits, &mt9p031->pll);
drivers/media/i2c/mt9p031.c
268
static int mt9p031_pll_enable(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
270
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
273
if (!mt9p031->use_pll)
drivers/media/i2c/mt9p031.c
282
(mt9p031->pll.m << 8) | (mt9p031->pll.n - 1));
drivers/media/i2c/mt9p031.c
286
ret = mt9p031_write(client, MT9P031_PLL_CONFIG_2, mt9p031->pll.p1 - 1);
drivers/media/i2c/mt9p031.c
297
static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
299
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
301
if (!mt9p031->use_pll)
drivers/media/i2c/mt9p031.c
308
static int mt9p031_power_on(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
314
if (mt9p031->reset) {
drivers/media/i2c/mt9p031.c
315
gpiod_set_value(mt9p031->reset, 1);
drivers/media/i2c/mt9p031.c
320
ret = regulator_bulk_enable(ARRAY_SIZE(mt9p031->regulators),
drivers/media/i2c/mt9p031.c
321
mt9p031->regulators);
drivers/media/i2c/mt9p031.c
326
if (mt9p031->clk) {
drivers/media/i2c/mt9p031.c
327
ret = clk_prepare_enable(mt9p031->clk);
drivers/media/i2c/mt9p031.c
329
regulator_bulk_disable(ARRAY_SIZE(mt9p031->regulators),
drivers/media/i2c/mt9p031.c
330
mt9p031->regulators);
drivers/media/i2c/mt9p031.c
336
if (mt9p031->reset) {
drivers/media/i2c/mt9p031.c
337
gpiod_set_value(mt9p031->reset, 0);
drivers/media/i2c/mt9p031.c
339
rate = clk_get_rate(mt9p031->clk);
drivers/media/i2c/mt9p031.c
349
static void mt9p031_power_off(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
351
if (mt9p031->reset) {
drivers/media/i2c/mt9p031.c
352
gpiod_set_value(mt9p031->reset, 1);
drivers/media/i2c/mt9p031.c
356
regulator_bulk_disable(ARRAY_SIZE(mt9p031->regulators),
drivers/media/i2c/mt9p031.c
357
mt9p031->regulators);
drivers/media/i2c/mt9p031.c
359
clk_disable_unprepare(mt9p031->clk);
drivers/media/i2c/mt9p031.c
362
static int __mt9p031_set_power(struct mt9p031 *mt9p031, bool on)
drivers/media/i2c/mt9p031.c
364
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
368
mt9p031_power_off(mt9p031);
drivers/media/i2c/mt9p031.c
372
ret = mt9p031_power_on(mt9p031);
drivers/media/i2c/mt9p031.c
376
ret = mt9p031_reset(mt9p031);
drivers/media/i2c/mt9p031.c
383
if (mt9p031->pixclk_pol) {
drivers/media/i2c/mt9p031.c
390
return v4l2_ctrl_handler_setup(&mt9p031->ctrls);
drivers/media/i2c/mt9p031.c
397
static int mt9p031_set_params(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
399
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
400
struct v4l2_mbus_framefmt *format = &mt9p031->format;
drivers/media/i2c/mt9p031.c
401
const struct v4l2_rect *crop = &mt9p031->crop;
drivers/media/i2c/mt9p031.c
464
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
483
ret = mt9p031_set_output_control(mt9p031,
drivers/media/i2c/mt9p031.c
488
return mt9p031_pll_disable(mt9p031);
drivers/media/i2c/mt9p031.c
491
ret = mt9p031_set_params(mt9p031);
drivers/media/i2c/mt9p031.c
496
ret = mt9p031_set_output_control(mt9p031, 0,
drivers/media/i2c/mt9p031.c
511
return mt9p031_pll_enable(mt9p031);
drivers/media/i2c/mt9p031.c
518
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
523
code->code = mt9p031->format.code;
drivers/media/i2c/mt9p031.c
531
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
533
if (fse->index >= 8 || fse->code != mt9p031->format.code)
drivers/media/i2c/mt9p031.c
546
__mt9p031_get_pad_format(struct mt9p031 *mt9p031,
drivers/media/i2c/mt9p031.c
554
return &mt9p031->format;
drivers/media/i2c/mt9p031.c
561
__mt9p031_get_pad_crop(struct mt9p031 *mt9p031,
drivers/media/i2c/mt9p031.c
569
return &mt9p031->crop;
drivers/media/i2c/mt9p031.c
579
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
581
fmt->format = *__mt9p031_get_pad_format(mt9p031, sd_state, fmt->pad,
drivers/media/i2c/mt9p031.c
590
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
598
__crop = __mt9p031_get_pad_crop(mt9p031, sd_state, format->pad,
drivers/media/i2c/mt9p031.c
614
__format = __mt9p031_get_pad_format(mt9p031, sd_state, format->pad,
drivers/media/i2c/mt9p031.c
628
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
639
sel->r = *__mt9p031_get_pad_crop(mt9p031, sd_state,
drivers/media/i2c/mt9p031.c
652
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
679
__crop = __mt9p031_get_pad_crop(mt9p031, sd_state, sel->pad,
drivers/media/i2c/mt9p031.c
686
__format = __mt9p031_get_pad_format(mt9p031, sd_state,
drivers/media/i2c/mt9p031.c
702
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
708
crop = __mt9p031_get_pad_crop(mt9p031, sd_state, 0, which);
drivers/media/i2c/mt9p031.c
714
format = __mt9p031_get_pad_format(mt9p031, sd_state, 0, which);
drivers/media/i2c/mt9p031.c
715
format->code = mt9p031->code;
drivers/media/i2c/mt9p031.c
733
static int mt9p031_restore_blc(struct mt9p031 *mt9p031)
drivers/media/i2c/mt9p031.c
735
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
738
if (mt9p031->blc_auto->cur.val != 0) {
drivers/media/i2c/mt9p031.c
739
ret = mt9p031_set_mode2(mt9p031, 0,
drivers/media/i2c/mt9p031.c
745
if (mt9p031->blc_offset->cur.val != 0) {
drivers/media/i2c/mt9p031.c
747
mt9p031->blc_offset->cur.val);
drivers/media/i2c/mt9p031.c
757
struct mt9p031 *mt9p031 =
drivers/media/i2c/mt9p031.c
758
container_of(ctrl->handler, struct mt9p031, ctrls);
drivers/media/i2c/mt9p031.c
759
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
drivers/media/i2c/mt9p031.c
806
return mt9p031_set_mode2(mt9p031,
drivers/media/i2c/mt9p031.c
809
return mt9p031_set_mode2(mt9p031,
drivers/media/i2c/mt9p031.c
814
return mt9p031_set_mode2(mt9p031,
drivers/media/i2c/mt9p031.c
817
return mt9p031_set_mode2(mt9p031,
drivers/media/i2c/mt9p031.c
826
v4l2_ctrl_activate(mt9p031->blc_auto, ctrl->val == 0);
drivers/media/i2c/mt9p031.c
827
v4l2_ctrl_activate(mt9p031->blc_offset, ctrl->val == 0);
drivers/media/i2c/mt9p031.c
831
ret = mt9p031_restore_blc(mt9p031);
drivers/media/i2c/mt9p031.c
849
ret = mt9p031_set_mode2(mt9p031, MT9P031_READ_MODE_2_ROW_BLC,
drivers/media/i2c/mt9p031.c
863
ret = mt9p031_set_mode2(mt9p031,
drivers/media/i2c/mt9p031.c
965
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
968
mutex_lock(&mt9p031->power_lock);
drivers/media/i2c/mt9p031.c
973
if (mt9p031->power_count == !on) {
drivers/media/i2c/mt9p031.c
974
ret = __mt9p031_set_power(mt9p031, !!on);
drivers/media/i2c/mt9p031.c
980
mt9p031->power_count += on ? 1 : -1;
drivers/media/i2c/mt9p031.c
981
WARN_ON(mt9p031->power_count < 0);
drivers/media/i2c/mt9p031.c
984
mutex_unlock(&mt9p031->power_lock);
drivers/media/i2c/mt9p031.c
995
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
drivers/media/i2c/mt9p031.c
999
ret = mt9p031_power_on(mt9p031);