Lines Matching +full:1 +full:- +full:sd
1 // SPDX-License-Identifier: GPL-2.0-only
19 #include <media/v4l2-ctrls.h>
20 #include <media/v4l2-device.h>
25 struct v4l2_subdev sd; member
37 * Mode 1 CVBS Input (Composite Video on AIN5)
38 * All standards are supported through autodetect, 8-bit, 4:2:2, ITU-R BT.656 output on P15 to P8.
44 ADV7183_ADC_CTRL, 0x16, /* Power down ADC 1 and ADC 2 */
63 static inline struct adv7183 *to_adv7183(struct v4l2_subdev *sd) in to_adv7183() argument
65 return container_of(sd, struct adv7183, sd); in to_adv7183()
69 return &container_of(ctrl->handler, struct adv7183, hdl)->sd; in to_sd()
72 static inline int adv7183_read(struct v4l2_subdev *sd, unsigned char reg) in adv7183_read() argument
74 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7183_read()
79 static inline int adv7183_write(struct v4l2_subdev *sd, unsigned char reg, in adv7183_write() argument
82 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7183_write()
87 static int adv7183_writeregs(struct v4l2_subdev *sd, in adv7183_writeregs() argument
94 v4l2_err(sd, "invalid regs array\n"); in adv7183_writeregs()
95 return -1; in adv7183_writeregs()
103 adv7183_write(sd, reg, data); in adv7183_writeregs()
108 static int adv7183_log_status(struct v4l2_subdev *sd) in adv7183_log_status() argument
110 struct adv7183 *decoder = to_adv7183(sd); in adv7183_log_status()
112 v4l2_info(sd, "adv7183: Input control = 0x%02x\n", in adv7183_log_status()
113 adv7183_read(sd, ADV7183_IN_CTRL)); in adv7183_log_status()
114 v4l2_info(sd, "adv7183: Video selection = 0x%02x\n", in adv7183_log_status()
115 adv7183_read(sd, ADV7183_VD_SEL)); in adv7183_log_status()
116 v4l2_info(sd, "adv7183: Output control = 0x%02x\n", in adv7183_log_status()
117 adv7183_read(sd, ADV7183_OUT_CTRL)); in adv7183_log_status()
118 v4l2_info(sd, "adv7183: Extended output control = 0x%02x\n", in adv7183_log_status()
119 adv7183_read(sd, ADV7183_EXT_OUT_CTRL)); in adv7183_log_status()
120 v4l2_info(sd, "adv7183: Autodetect enable = 0x%02x\n", in adv7183_log_status()
121 adv7183_read(sd, ADV7183_AUTO_DET_EN)); in adv7183_log_status()
122 v4l2_info(sd, "adv7183: Contrast = 0x%02x\n", in adv7183_log_status()
123 adv7183_read(sd, ADV7183_CONTRAST)); in adv7183_log_status()
124 v4l2_info(sd, "adv7183: Brightness = 0x%02x\n", in adv7183_log_status()
125 adv7183_read(sd, ADV7183_BRIGHTNESS)); in adv7183_log_status()
126 v4l2_info(sd, "adv7183: Hue = 0x%02x\n", in adv7183_log_status()
127 adv7183_read(sd, ADV7183_HUE)); in adv7183_log_status()
128 v4l2_info(sd, "adv7183: Default value Y = 0x%02x\n", in adv7183_log_status()
129 adv7183_read(sd, ADV7183_DEF_Y)); in adv7183_log_status()
130 v4l2_info(sd, "adv7183: Default value C = 0x%02x\n", in adv7183_log_status()
131 adv7183_read(sd, ADV7183_DEF_C)); in adv7183_log_status()
132 v4l2_info(sd, "adv7183: ADI control = 0x%02x\n", in adv7183_log_status()
133 adv7183_read(sd, ADV7183_ADI_CTRL)); in adv7183_log_status()
134 v4l2_info(sd, "adv7183: Power Management = 0x%02x\n", in adv7183_log_status()
135 adv7183_read(sd, ADV7183_POW_MANAGE)); in adv7183_log_status()
136 v4l2_info(sd, "adv7183: Status 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n", in adv7183_log_status()
137 adv7183_read(sd, ADV7183_STATUS_1), in adv7183_log_status()
138 adv7183_read(sd, ADV7183_STATUS_2), in adv7183_log_status()
139 adv7183_read(sd, ADV7183_STATUS_3)); in adv7183_log_status()
140 v4l2_info(sd, "adv7183: Ident = 0x%02x\n", in adv7183_log_status()
141 adv7183_read(sd, ADV7183_IDENT)); in adv7183_log_status()
142 v4l2_info(sd, "adv7183: Analog clamp control = 0x%02x\n", in adv7183_log_status()
143 adv7183_read(sd, ADV7183_ANAL_CLAMP_CTRL)); in adv7183_log_status()
144 v4l2_info(sd, "adv7183: Digital clamp control 1 = 0x%02x\n", in adv7183_log_status()
145 adv7183_read(sd, ADV7183_DIGI_CLAMP_CTRL_1)); in adv7183_log_status()
146 v4l2_info(sd, "adv7183: Shaping filter control 1 and 2 = 0x%02x 0x%02x\n", in adv7183_log_status()
147 adv7183_read(sd, ADV7183_SHAP_FILT_CTRL), in adv7183_log_status()
148 adv7183_read(sd, ADV7183_SHAP_FILT_CTRL_2)); in adv7183_log_status()
149 v4l2_info(sd, "adv7183: Comb filter control = 0x%02x\n", in adv7183_log_status()
150 adv7183_read(sd, ADV7183_COMB_FILT_CTRL)); in adv7183_log_status()
151 v4l2_info(sd, "adv7183: ADI control 2 = 0x%02x\n", in adv7183_log_status()
152 adv7183_read(sd, ADV7183_ADI_CTRL_2)); in adv7183_log_status()
153 v4l2_info(sd, "adv7183: Pixel delay control = 0x%02x\n", in adv7183_log_status()
154 adv7183_read(sd, ADV7183_PIX_DELAY_CTRL)); in adv7183_log_status()
155 v4l2_info(sd, "adv7183: Misc gain control = 0x%02x\n", in adv7183_log_status()
156 adv7183_read(sd, ADV7183_MISC_GAIN_CTRL)); in adv7183_log_status()
157 v4l2_info(sd, "adv7183: AGC mode control = 0x%02x\n", in adv7183_log_status()
158 adv7183_read(sd, ADV7183_AGC_MODE_CTRL)); in adv7183_log_status()
159 v4l2_info(sd, "adv7183: Chroma gain control 1 and 2 = 0x%02x 0x%02x\n", in adv7183_log_status()
160 adv7183_read(sd, ADV7183_CHRO_GAIN_CTRL_1), in adv7183_log_status()
161 adv7183_read(sd, ADV7183_CHRO_GAIN_CTRL_2)); in adv7183_log_status()
162 v4l2_info(sd, "adv7183: Luma gain control 1 and 2 = 0x%02x 0x%02x\n", in adv7183_log_status()
163 adv7183_read(sd, ADV7183_LUMA_GAIN_CTRL_1), in adv7183_log_status()
164 adv7183_read(sd, ADV7183_LUMA_GAIN_CTRL_2)); in adv7183_log_status()
165 v4l2_info(sd, "adv7183: Vsync field control 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n", in adv7183_log_status()
166 adv7183_read(sd, ADV7183_VS_FIELD_CTRL_1), in adv7183_log_status()
167 adv7183_read(sd, ADV7183_VS_FIELD_CTRL_2), in adv7183_log_status()
168 adv7183_read(sd, ADV7183_VS_FIELD_CTRL_3)); in adv7183_log_status()
169 v4l2_info(sd, "adv7183: Hsync position control 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n", in adv7183_log_status()
170 adv7183_read(sd, ADV7183_HS_POS_CTRL_1), in adv7183_log_status()
171 adv7183_read(sd, ADV7183_HS_POS_CTRL_2), in adv7183_log_status()
172 adv7183_read(sd, ADV7183_HS_POS_CTRL_3)); in adv7183_log_status()
173 v4l2_info(sd, "adv7183: Polarity = 0x%02x\n", in adv7183_log_status()
174 adv7183_read(sd, ADV7183_POLARITY)); in adv7183_log_status()
175 v4l2_info(sd, "adv7183: ADC control = 0x%02x\n", in adv7183_log_status()
176 adv7183_read(sd, ADV7183_ADC_CTRL)); in adv7183_log_status()
177 v4l2_info(sd, "adv7183: SD offset Cb and Cr = 0x%02x 0x%02x\n", in adv7183_log_status()
178 adv7183_read(sd, ADV7183_SD_OFFSET_CB), in adv7183_log_status()
179 adv7183_read(sd, ADV7183_SD_OFFSET_CR)); in adv7183_log_status()
180 v4l2_info(sd, "adv7183: SD saturation Cb and Cr = 0x%02x 0x%02x\n", in adv7183_log_status()
181 adv7183_read(sd, ADV7183_SD_SATURATION_CB), in adv7183_log_status()
182 adv7183_read(sd, ADV7183_SD_SATURATION_CR)); in adv7183_log_status()
183 v4l2_info(sd, "adv7183: Drive strength = 0x%02x\n", in adv7183_log_status()
184 adv7183_read(sd, ADV7183_DRIVE_STR)); in adv7183_log_status()
185 v4l2_ctrl_handler_log_status(&decoder->hdl, sd->name); in adv7183_log_status()
189 static int adv7183_g_std(struct v4l2_subdev *sd, v4l2_std_id *std) in adv7183_g_std() argument
191 struct adv7183 *decoder = to_adv7183(sd); in adv7183_g_std()
193 *std = decoder->std; in adv7183_g_std()
197 static int adv7183_s_std(struct v4l2_subdev *sd, v4l2_std_id std) in adv7183_s_std() argument
199 struct adv7183 *decoder = to_adv7183(sd); in adv7183_s_std()
202 reg = adv7183_read(sd, ADV7183_IN_CTRL) & 0xF; in adv7183_s_std()
220 return -EINVAL; in adv7183_s_std()
221 adv7183_write(sd, ADV7183_IN_CTRL, reg); in adv7183_s_std()
223 decoder->std = std; in adv7183_s_std()
228 static int adv7183_reset(struct v4l2_subdev *sd, u32 val) in adv7183_reset() argument
232 reg = adv7183_read(sd, ADV7183_POW_MANAGE) | 0x80; in adv7183_reset()
233 adv7183_write(sd, ADV7183_POW_MANAGE, reg); in adv7183_reset()
239 static int adv7183_s_routing(struct v4l2_subdev *sd, in adv7183_s_routing() argument
242 struct adv7183 *decoder = to_adv7183(sd); in adv7183_s_routing()
246 return -EINVAL; in adv7183_s_routing()
248 if (input != decoder->input) { in adv7183_s_routing()
249 decoder->input = input; in adv7183_s_routing()
250 reg = adv7183_read(sd, ADV7183_IN_CTRL) & 0xF0; in adv7183_s_routing()
300 adv7183_write(sd, ADV7183_IN_CTRL, reg); in adv7183_s_routing()
303 if (output != decoder->output) { in adv7183_s_routing()
304 decoder->output = output; in adv7183_s_routing()
305 reg = adv7183_read(sd, ADV7183_OUT_CTRL) & 0xC0; in adv7183_s_routing()
314 adv7183_write(sd, ADV7183_OUT_CTRL, reg); in adv7183_s_routing()
322 struct v4l2_subdev *sd = to_sd(ctrl); in adv7183_s_ctrl() local
323 int val = ctrl->val; in adv7183_s_ctrl()
325 switch (ctrl->id) { in adv7183_s_ctrl()
328 val = 127 - val; in adv7183_s_ctrl()
329 adv7183_write(sd, ADV7183_BRIGHTNESS, val); in adv7183_s_ctrl()
332 adv7183_write(sd, ADV7183_CONTRAST, val); in adv7183_s_ctrl()
335 adv7183_write(sd, ADV7183_SD_SATURATION_CB, val >> 8); in adv7183_s_ctrl()
336 adv7183_write(sd, ADV7183_SD_SATURATION_CR, (val & 0xFF)); in adv7183_s_ctrl()
339 adv7183_write(sd, ADV7183_SD_OFFSET_CB, val >> 8); in adv7183_s_ctrl()
340 adv7183_write(sd, ADV7183_SD_OFFSET_CR, (val & 0xFF)); in adv7183_s_ctrl()
343 return -EINVAL; in adv7183_s_ctrl()
349 static int adv7183_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) in adv7183_querystd() argument
351 struct adv7183 *decoder = to_adv7183(sd); in adv7183_querystd()
355 reg = adv7183_read(sd, ADV7183_IN_CTRL) & 0xF; in adv7183_querystd()
356 adv7183_write(sd, ADV7183_IN_CTRL, reg); in adv7183_querystd()
362 reg = adv7183_read(sd, ADV7183_STATUS_1); in adv7183_querystd()
367 case 1: in adv7183_querystd()
394 adv7183_s_std(sd, decoder->std); in adv7183_querystd()
398 static int adv7183_g_input_status(struct v4l2_subdev *sd, u32 *status) in adv7183_g_input_status() argument
403 reg = adv7183_read(sd, ADV7183_STATUS_1); in adv7183_g_input_status()
411 static int adv7183_enum_mbus_code(struct v4l2_subdev *sd, in adv7183_enum_mbus_code() argument
415 if (code->pad || code->index > 0) in adv7183_enum_mbus_code()
416 return -EINVAL; in adv7183_enum_mbus_code()
418 code->code = MEDIA_BUS_FMT_UYVY8_2X8; in adv7183_enum_mbus_code()
422 static int adv7183_set_fmt(struct v4l2_subdev *sd, in adv7183_set_fmt() argument
426 struct adv7183 *decoder = to_adv7183(sd); in adv7183_set_fmt()
427 struct v4l2_mbus_framefmt *fmt = &format->format; in adv7183_set_fmt()
429 if (format->pad) in adv7183_set_fmt()
430 return -EINVAL; in adv7183_set_fmt()
432 fmt->code = MEDIA_BUS_FMT_UYVY8_2X8; in adv7183_set_fmt()
433 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; in adv7183_set_fmt()
434 if (decoder->std & V4L2_STD_525_60) { in adv7183_set_fmt()
435 fmt->field = V4L2_FIELD_SEQ_TB; in adv7183_set_fmt()
436 fmt->width = 720; in adv7183_set_fmt()
437 fmt->height = 480; in adv7183_set_fmt()
439 fmt->field = V4L2_FIELD_SEQ_BT; in adv7183_set_fmt()
440 fmt->width = 720; in adv7183_set_fmt()
441 fmt->height = 576; in adv7183_set_fmt()
443 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) in adv7183_set_fmt()
444 decoder->fmt = *fmt; in adv7183_set_fmt()
448 static int adv7183_get_fmt(struct v4l2_subdev *sd, in adv7183_get_fmt() argument
452 struct adv7183 *decoder = to_adv7183(sd); in adv7183_get_fmt()
454 if (format->pad) in adv7183_get_fmt()
455 return -EINVAL; in adv7183_get_fmt()
457 format->format = decoder->fmt; in adv7183_get_fmt()
461 static int adv7183_s_stream(struct v4l2_subdev *sd, int enable) in adv7183_s_stream() argument
463 struct adv7183 *decoder = to_adv7183(sd); in adv7183_s_stream()
466 gpiod_set_value(decoder->oe_pin, 1); in adv7183_s_stream()
468 gpiod_set_value(decoder->oe_pin, 0); in adv7183_s_stream()
469 udelay(1); in adv7183_s_stream()
474 static int adv7183_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) in adv7183_g_register() argument
476 reg->val = adv7183_read(sd, reg->reg & 0xff); in adv7183_g_register()
477 reg->size = 1; in adv7183_g_register()
481 static int adv7183_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) in adv7183_s_register() argument
483 adv7183_write(sd, reg->reg & 0xff, reg->val & 0xff); in adv7183_s_register()
525 struct v4l2_subdev *sd; in adv7183_probe() local
533 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in adv7183_probe()
534 return -EIO; in adv7183_probe()
537 client->addr << 1, client->adapter->name); in adv7183_probe()
539 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); in adv7183_probe()
541 return -ENOMEM; in adv7183_probe()
547 decoder->reset_pin = devm_gpiod_get(&client->dev, "reset", in adv7183_probe()
549 if (IS_ERR(decoder->reset_pin)) in adv7183_probe()
550 return PTR_ERR(decoder->reset_pin); in adv7183_probe()
551 gpiod_set_consumer_name(decoder->reset_pin, "ADV7183 Reset"); in adv7183_probe()
556 decoder->oe_pin = devm_gpiod_get(&client->dev, "oe", in adv7183_probe()
558 if (IS_ERR(decoder->oe_pin)) in adv7183_probe()
559 return PTR_ERR(decoder->oe_pin); in adv7183_probe()
560 gpiod_set_consumer_name(decoder->reset_pin, "ADV7183 Output Enable"); in adv7183_probe()
562 sd = &decoder->sd; in adv7183_probe()
563 v4l2_i2c_subdev_init(sd, client, &adv7183_ops); in adv7183_probe()
565 hdl = &decoder->hdl; in adv7183_probe()
568 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0); in adv7183_probe()
570 V4L2_CID_CONTRAST, 0, 0xFF, 1, 0x80); in adv7183_probe()
572 V4L2_CID_SATURATION, 0, 0xFFFF, 1, 0x8080); in adv7183_probe()
574 V4L2_CID_HUE, 0, 0xFFFF, 1, 0x8080); in adv7183_probe()
576 sd->ctrl_handler = hdl; in adv7183_probe()
577 if (hdl->error) { in adv7183_probe()
578 ret = hdl->error; in adv7183_probe()
585 decoder->std = V4L2_STD_PAL; in adv7183_probe()
586 decoder->input = ADV7183_COMPOSITE4; in adv7183_probe()
587 decoder->output = ADV7183_8BIT_OUT; in adv7183_probe()
592 /* De-assert reset line (descriptor tagged active low) */ in adv7183_probe()
593 gpiod_set_value(decoder->reset_pin, 0); in adv7183_probe()
597 adv7183_writeregs(sd, adv7183_init_regs, ARRAY_SIZE(adv7183_init_regs)); in adv7183_probe()
598 adv7183_s_std(sd, decoder->std); in adv7183_probe()
601 adv7183_set_fmt(sd, NULL, &fmt); in adv7183_probe()
615 struct v4l2_subdev *sd = i2c_get_clientdata(client); in adv7183_remove() local
617 v4l2_device_unregister_subdev(sd); in adv7183_remove()
618 v4l2_ctrl_handler_free(sd->ctrl_handler); in adv7183_remove()