Lines Matching +full:1 +full:- +full:sd

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * vpx3220a, vpx3216b & vpx3214c video decoder driver version 0.0.1
16 #include <media/v4l2-device.h>
17 #include <media/v4l2-ctrls.h>
25 MODULE_PARM_DESC(debug, "Debug level (0-1)");
30 /* ----------------------------------------------------------------------- */
33 struct v4l2_subdev sd; member
42 static inline struct vpx3220 *to_vpx3220(struct v4l2_subdev *sd) in to_vpx3220() argument
44 return container_of(sd, struct vpx3220, sd); in to_vpx3220()
49 return &container_of(ctrl->handler, struct vpx3220, hdl)->sd; in to_sd()
54 /* ----------------------------------------------------------------------- */
56 static inline int vpx3220_write(struct v4l2_subdev *sd, u8 reg, u8 value) in vpx3220_write() argument
58 struct i2c_client *client = v4l2_get_subdevdata(sd); in vpx3220_write()
61 decoder->reg[reg] = value; in vpx3220_write()
65 static inline int vpx3220_read(struct v4l2_subdev *sd, u8 reg) in vpx3220_read() argument
67 struct i2c_client *client = v4l2_get_subdevdata(sd); in vpx3220_read()
72 static int vpx3220_fp_status(struct v4l2_subdev *sd) in vpx3220_fp_status() argument
78 status = vpx3220_read(sd, 0x29); in vpx3220_fp_status()
89 return -1; in vpx3220_fp_status()
92 static int vpx3220_fp_write(struct v4l2_subdev *sd, u8 fpaddr, u16 data) in vpx3220_fp_write() argument
94 struct i2c_client *client = v4l2_get_subdevdata(sd); in vpx3220_fp_write()
96 /* Write the 16-bit address to the FPWR register */ in vpx3220_fp_write()
97 if (i2c_smbus_write_word_data(client, 0x27, swab16(fpaddr)) == -1) { in vpx3220_fp_write()
98 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__); in vpx3220_fp_write()
99 return -1; in vpx3220_fp_write()
102 if (vpx3220_fp_status(sd) < 0) in vpx3220_fp_write()
103 return -1; in vpx3220_fp_write()
105 /* Write the 16-bit data to the FPDAT register */ in vpx3220_fp_write()
106 if (i2c_smbus_write_word_data(client, 0x28, swab16(data)) == -1) { in vpx3220_fp_write()
107 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__); in vpx3220_fp_write()
108 return -1; in vpx3220_fp_write()
114 static int vpx3220_fp_read(struct v4l2_subdev *sd, u16 fpaddr) in vpx3220_fp_read() argument
116 struct i2c_client *client = v4l2_get_subdevdata(sd); in vpx3220_fp_read()
119 /* Write the 16-bit address to the FPRD register */ in vpx3220_fp_read()
120 if (i2c_smbus_write_word_data(client, 0x26, swab16(fpaddr)) == -1) { in vpx3220_fp_read()
121 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__); in vpx3220_fp_read()
122 return -1; in vpx3220_fp_read()
125 if (vpx3220_fp_status(sd) < 0) in vpx3220_fp_read()
126 return -1; in vpx3220_fp_read()
128 /* Read the 16-bit data from the FPDAT register */ in vpx3220_fp_read()
130 if (data == -1) { in vpx3220_fp_read()
131 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__); in vpx3220_fp_read()
132 return -1; in vpx3220_fp_read()
138 static int vpx3220_write_block(struct v4l2_subdev *sd, const u8 *data, unsigned int len) in vpx3220_write_block() argument
141 int ret = -1; in vpx3220_write_block()
145 ret = vpx3220_write(sd, reg, *data++); in vpx3220_write_block()
148 len -= 2; in vpx3220_write_block()
154 static int vpx3220_write_fp_block(struct v4l2_subdev *sd, in vpx3220_write_fp_block() argument
160 while (len > 1) { in vpx3220_write_fp_block()
162 ret |= vpx3220_fp_write(sd, reg, *data++); in vpx3220_write_fp_block()
163 len -= 2; in vpx3220_write_fp_block()
169 /* ---------------------------------------------------------------------- */
173 0x88, 17, /* Window 1 vertical */
188 0x88, 23, /* Window 1 vertical begin */
205 0x88, 23, /* Window 1 vertical begin */
236 * 10 to 8 2-bit error diffusion */
265 static int vpx3220_init(struct v4l2_subdev *sd, u32 val) in vpx3220_init() argument
267 struct vpx3220 *decoder = to_vpx3220(sd); in vpx3220_init()
269 vpx3220_write_block(sd, init_common, sizeof(init_common)); in vpx3220_init()
270 vpx3220_write_fp_block(sd, init_fp, sizeof(init_fp) >> 1); in vpx3220_init()
271 if (decoder->norm & V4L2_STD_NTSC) in vpx3220_init()
272 vpx3220_write_fp_block(sd, init_ntsc, sizeof(init_ntsc) >> 1); in vpx3220_init()
273 else if (decoder->norm & V4L2_STD_PAL) in vpx3220_init()
274 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1); in vpx3220_init()
275 else if (decoder->norm & V4L2_STD_SECAM) in vpx3220_init()
276 vpx3220_write_fp_block(sd, init_secam, sizeof(init_secam) >> 1); in vpx3220_init()
278 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1); in vpx3220_init()
282 static int vpx3220_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd) in vpx3220_status() argument
287 status = vpx3220_fp_read(sd, 0x0f3); in vpx3220_status()
289 v4l2_dbg(1, debug, sd, "status: 0x%04x\n", status); in vpx3220_status()
325 static int vpx3220_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) in vpx3220_querystd() argument
327 v4l2_dbg(1, debug, sd, "querystd\n"); in vpx3220_querystd()
328 return vpx3220_status(sd, NULL, std); in vpx3220_querystd()
331 static int vpx3220_g_input_status(struct v4l2_subdev *sd, u32 *status) in vpx3220_g_input_status() argument
333 v4l2_dbg(1, debug, sd, "g_input_status\n"); in vpx3220_g_input_status()
334 return vpx3220_status(sd, status, NULL); in vpx3220_g_input_status()
337 static int vpx3220_s_std(struct v4l2_subdev *sd, v4l2_std_id std) in vpx3220_s_std() argument
339 struct vpx3220 *decoder = to_vpx3220(sd); in vpx3220_s_std()
345 temp_input = vpx3220_fp_read(sd, 0xf2); in vpx3220_s_std()
347 v4l2_dbg(1, debug, sd, "s_std %llx\n", (unsigned long long)std); in vpx3220_s_std()
349 vpx3220_write_fp_block(sd, init_ntsc, sizeof(init_ntsc) >> 1); in vpx3220_s_std()
350 v4l2_dbg(1, debug, sd, "norm switched to NTSC\n"); in vpx3220_s_std()
352 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1); in vpx3220_s_std()
353 v4l2_dbg(1, debug, sd, "norm switched to PAL\n"); in vpx3220_s_std()
355 vpx3220_write_fp_block(sd, init_secam, sizeof(init_secam) >> 1); in vpx3220_s_std()
356 v4l2_dbg(1, debug, sd, "norm switched to SECAM\n"); in vpx3220_s_std()
358 return -EINVAL; in vpx3220_s_std()
361 decoder->norm = std; in vpx3220_s_std()
364 vpx3220_fp_write(sd, 0xf2, temp_input | 0x0010); in vpx3220_s_std()
369 static int vpx3220_s_routing(struct v4l2_subdev *sd, in vpx3220_s_routing() argument
375 input = 1: COMPOSITE input in vpx3220_s_routing()
381 {0x0e, 1} in vpx3220_s_routing()
385 return -EINVAL; in vpx3220_s_routing()
387 v4l2_dbg(1, debug, sd, "input switched to %s\n", inputs[input]); in vpx3220_s_routing()
389 vpx3220_write(sd, 0x33, input_vals[input][0]); in vpx3220_s_routing()
391 data = vpx3220_fp_read(sd, 0xf2) & ~(0x0020); in vpx3220_s_routing()
395 vpx3220_fp_write(sd, 0xf2, in vpx3220_s_routing()
396 data | (input_vals[input][1] << 5) | 0x0010); in vpx3220_s_routing()
402 static int vpx3220_s_stream(struct v4l2_subdev *sd, int enable) in vpx3220_s_stream() argument
404 v4l2_dbg(1, debug, sd, "s_stream %s\n", enable ? "on" : "off"); in vpx3220_s_stream()
406 vpx3220_write(sd, 0xf2, (enable ? 0x1b : 0x00)); in vpx3220_s_stream()
412 struct v4l2_subdev *sd = to_sd(ctrl); in vpx3220_s_ctrl() local
414 switch (ctrl->id) { in vpx3220_s_ctrl()
416 vpx3220_write(sd, 0xe6, ctrl->val); in vpx3220_s_ctrl()
420 vpx3220_write(sd, 0xe7, ctrl->val + 192); in vpx3220_s_ctrl()
423 vpx3220_fp_write(sd, 0xa0, ctrl->val); in vpx3220_s_ctrl()
426 vpx3220_fp_write(sd, 0x1c, ctrl->val); in vpx3220_s_ctrl()
429 return -EINVAL; in vpx3220_s_ctrl()
432 /* ----------------------------------------------------------------------- */
455 /* -----------------------------------------------------------------------
462 struct v4l2_subdev *sd; in vpx3220_probe() local
468 if (!i2c_check_functionality(client->adapter, in vpx3220_probe()
470 return -ENODEV; in vpx3220_probe()
472 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); in vpx3220_probe()
474 return -ENOMEM; in vpx3220_probe()
475 sd = &decoder->sd; in vpx3220_probe()
476 v4l2_i2c_subdev_init(sd, client, &vpx3220_ops); in vpx3220_probe()
477 decoder->norm = V4L2_STD_PAL; in vpx3220_probe()
478 decoder->input = 0; in vpx3220_probe()
479 decoder->enable = 1; in vpx3220_probe()
480 v4l2_ctrl_handler_init(&decoder->hdl, 4); in vpx3220_probe()
481 v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, in vpx3220_probe()
482 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0); in vpx3220_probe()
483 v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, in vpx3220_probe()
484 V4L2_CID_CONTRAST, 0, 63, 1, 32); in vpx3220_probe()
485 v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, in vpx3220_probe()
486 V4L2_CID_SATURATION, 0, 4095, 1, 2048); in vpx3220_probe()
487 v4l2_ctrl_new_std(&decoder->hdl, &vpx3220_ctrl_ops, in vpx3220_probe()
488 V4L2_CID_HUE, -512, 511, 1, 0); in vpx3220_probe()
489 sd->ctrl_handler = &decoder->hdl; in vpx3220_probe()
490 if (decoder->hdl.error) { in vpx3220_probe()
491 int err = decoder->hdl.error; in vpx3220_probe()
493 v4l2_ctrl_handler_free(&decoder->hdl); in vpx3220_probe()
496 v4l2_ctrl_handler_setup(&decoder->hdl); in vpx3220_probe()
515 v4l2_info(sd, "%s found @ 0x%x (%s)\n", name, in vpx3220_probe()
516 client->addr << 1, client->adapter->name); in vpx3220_probe()
518 v4l2_info(sd, "chip (%02x:%04x) found @ 0x%x (%s)\n", in vpx3220_probe()
519 ver, pn, client->addr << 1, client->adapter->name); in vpx3220_probe()
521 vpx3220_write_block(sd, init_common, sizeof(init_common)); in vpx3220_probe()
522 vpx3220_write_fp_block(sd, init_fp, sizeof(init_fp) >> 1); in vpx3220_probe()
524 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1); in vpx3220_probe()
530 struct v4l2_subdev *sd = i2c_get_clientdata(client); in vpx3220_remove() local
531 struct vpx3220 *decoder = to_vpx3220(sd); in vpx3220_remove()
533 v4l2_device_unregister_subdev(sd); in vpx3220_remove()
534 v4l2_ctrl_handler_free(&decoder->hdl); in vpx3220_remove()