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

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * saa7110 - Philips SAA7110(A) video decoder driver
9 * - some corrections for Pinnacle Systems Inc. DC10plus card.
12 * - moved over to linux>=2.4.x i2c protocol (1/1/2003)
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-ctrls.h>
34 MODULE_PARM_DESC(debug, "Debug level (0-1)");
37 #define SAA7110_MAX_OUTPUT 1 /* 1 YUV */
42 struct v4l2_subdev sd; member
53 static inline struct saa7110 *to_saa7110(struct v4l2_subdev *sd) in to_saa7110() argument
55 return container_of(sd, struct saa7110, sd); in to_saa7110()
60 return &container_of(ctrl->handler, struct saa7110, hdl)->sd; in to_sd()
63 /* ----------------------------------------------------------------------- */
65 /* ----------------------------------------------------------------------- */
67 static int saa7110_write(struct v4l2_subdev *sd, u8 reg, u8 value) in saa7110_write() argument
69 struct i2c_client *client = v4l2_get_subdevdata(sd); in saa7110_write()
70 struct saa7110 *decoder = to_saa7110(sd); in saa7110_write()
72 decoder->reg[reg] = value; in saa7110_write()
76 static int saa7110_write_block(struct v4l2_subdev *sd, const u8 *data, unsigned int len) in saa7110_write_block() argument
78 struct i2c_client *client = v4l2_get_subdevdata(sd); in saa7110_write_block()
79 struct saa7110 *decoder = to_saa7110(sd); in saa7110_write_block()
80 int ret = -1; in saa7110_write_block()
84 if (reg + (len - 1) > SAA7110_NR_REG) in saa7110_write_block()
89 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in saa7110_write_block()
93 memcpy(decoder->reg + reg, data + 1, len - 1); in saa7110_write_block()
95 for (++data, --len; len; len--) { in saa7110_write_block()
96 ret = saa7110_write(sd, reg++, *data++); in saa7110_write_block()
105 static inline int saa7110_read(struct v4l2_subdev *sd) in saa7110_read() argument
107 struct i2c_client *client = v4l2_get_subdevdata(sd); in saa7110_read()
112 /* ----------------------------------------------------------------------- */
114 /* ----------------------------------------------------------------------- */
120 static int saa7110_selmux(struct v4l2_subdev *sd, int chan) in saa7110_selmux() argument
126 /* mode 1 */ in saa7110_selmux()
151 struct saa7110 *decoder = to_saa7110(sd); in saa7110_selmux()
154 saa7110_write(sd, 0x06, ptr[0]); /* Luminance control */ in saa7110_selmux()
155 saa7110_write(sd, 0x20, ptr[1]); /* Analog Control #1 */ in saa7110_selmux()
156 saa7110_write(sd, 0x21, ptr[2]); /* Analog Control #2 */ in saa7110_selmux()
157 saa7110_write(sd, 0x22, ptr[3]); /* Mixer Control #1 */ in saa7110_selmux()
158 saa7110_write(sd, 0x2C, ptr[4]); /* Mixer Control #2 */ in saa7110_selmux()
159 saa7110_write(sd, 0x30, ptr[5]); /* ADCs gain control */ in saa7110_selmux()
160 saa7110_write(sd, 0x31, ptr[6]); /* Mixer Control #3 */ in saa7110_selmux()
161 saa7110_write(sd, 0x21, ptr[7]); /* Analog Control #2 */ in saa7110_selmux()
162 decoder->input = chan; in saa7110_selmux()
167 static const unsigned char initseq[1 + SAA7110_NR_REG] = {
177 static v4l2_std_id determine_norm(struct v4l2_subdev *sd) in determine_norm() argument
180 struct saa7110 *decoder = to_saa7110(sd); in determine_norm()
184 saa7110_write_block(sd, initseq, sizeof(initseq)); in determine_norm()
185 saa7110_selmux(sd, decoder->input); in determine_norm()
186 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); in determine_norm()
188 finish_wait(&decoder->wq, &wait); in determine_norm()
189 status = saa7110_read(sd); in determine_norm()
191 v4l2_dbg(1, debug, sd, "status=0x%02x (no signal)\n", status); in determine_norm()
195 saa7110_write(sd, 0x06, 0x83); in determine_norm()
197 v4l2_dbg(1, debug, sd, "status=0x%02x (NTSC/no color)\n", status); in determine_norm()
198 /*saa7110_write(sd,0x2E,0x81);*/ in determine_norm()
201 v4l2_dbg(1, debug, sd, "status=0x%02x (PAL/no color)\n", status); in determine_norm()
202 /*saa7110_write(sd,0x2E,0x9A);*/ in determine_norm()
205 /*saa7110_write(sd,0x06,0x03);*/ in determine_norm()
207 v4l2_dbg(1, debug, sd, "status=0x%02x (NTSC)\n", status); in determine_norm()
208 saa7110_write(sd, 0x0D, 0x86); in determine_norm()
209 saa7110_write(sd, 0x0F, 0x50); in determine_norm()
210 saa7110_write(sd, 0x11, 0x2C); in determine_norm()
211 /*saa7110_write(sd,0x2E,0x81);*/ in determine_norm()
215 /* 50Hz -> PAL/SECAM */ in determine_norm()
216 saa7110_write(sd, 0x0D, 0x86); in determine_norm()
217 saa7110_write(sd, 0x0F, 0x10); in determine_norm()
218 saa7110_write(sd, 0x11, 0x59); in determine_norm()
219 /*saa7110_write(sd,0x2E,0x9A);*/ in determine_norm()
221 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); in determine_norm()
223 finish_wait(&decoder->wq, &wait); in determine_norm()
225 status = saa7110_read(sd); in determine_norm()
227 v4l2_dbg(1, debug, sd, "status=0x%02x (SECAM)\n", status); in determine_norm()
228 saa7110_write(sd, 0x0D, 0x87); in determine_norm()
231 v4l2_dbg(1, debug, sd, "status=0x%02x (PAL)\n", status); in determine_norm()
235 static int saa7110_g_input_status(struct v4l2_subdev *sd, u32 *pstatus) in saa7110_g_input_status() argument
237 struct saa7110 *decoder = to_saa7110(sd); in saa7110_g_input_status()
239 int status = saa7110_read(sd); in saa7110_g_input_status()
241 v4l2_dbg(1, debug, sd, "status=0x%02x norm=%llx\n", in saa7110_g_input_status()
242 status, (unsigned long long)decoder->norm); in saa7110_g_input_status()
252 static int saa7110_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) in saa7110_querystd() argument
254 *std &= determine_norm(sd); in saa7110_querystd()
258 static int saa7110_s_std(struct v4l2_subdev *sd, v4l2_std_id std) in saa7110_s_std() argument
260 struct saa7110 *decoder = to_saa7110(sd); in saa7110_s_std()
262 if (decoder->norm != std) { in saa7110_s_std()
263 decoder->norm = std; in saa7110_s_std()
264 /*saa7110_write(sd, 0x06, 0x03);*/ in saa7110_s_std()
266 saa7110_write(sd, 0x0D, 0x86); in saa7110_s_std()
267 saa7110_write(sd, 0x0F, 0x50); in saa7110_s_std()
268 saa7110_write(sd, 0x11, 0x2C); in saa7110_s_std()
269 /*saa7110_write(sd, 0x2E, 0x81);*/ in saa7110_s_std()
270 v4l2_dbg(1, debug, sd, "switched to NTSC\n"); in saa7110_s_std()
272 saa7110_write(sd, 0x0D, 0x86); in saa7110_s_std()
273 saa7110_write(sd, 0x0F, 0x10); in saa7110_s_std()
274 saa7110_write(sd, 0x11, 0x59); in saa7110_s_std()
275 /*saa7110_write(sd, 0x2E, 0x9A);*/ in saa7110_s_std()
276 v4l2_dbg(1, debug, sd, "switched to PAL\n"); in saa7110_s_std()
278 saa7110_write(sd, 0x0D, 0x87); in saa7110_s_std()
279 saa7110_write(sd, 0x0F, 0x10); in saa7110_s_std()
280 saa7110_write(sd, 0x11, 0x59); in saa7110_s_std()
281 /*saa7110_write(sd, 0x2E, 0x9A);*/ in saa7110_s_std()
282 v4l2_dbg(1, debug, sd, "switched to SECAM\n"); in saa7110_s_std()
284 return -EINVAL; in saa7110_s_std()
290 static int saa7110_s_routing(struct v4l2_subdev *sd, in saa7110_s_routing() argument
293 struct saa7110 *decoder = to_saa7110(sd); in saa7110_s_routing()
296 v4l2_dbg(1, debug, sd, "input=%d not available\n", input); in saa7110_s_routing()
297 return -EINVAL; in saa7110_s_routing()
299 if (decoder->input != input) { in saa7110_s_routing()
300 saa7110_selmux(sd, input); in saa7110_s_routing()
301 v4l2_dbg(1, debug, sd, "switched to input=%d\n", input); in saa7110_s_routing()
306 static int saa7110_s_stream(struct v4l2_subdev *sd, int enable) in saa7110_s_stream() argument
308 struct saa7110 *decoder = to_saa7110(sd); in saa7110_s_stream()
310 if (decoder->enable != enable) { in saa7110_s_stream()
311 decoder->enable = enable; in saa7110_s_stream()
312 saa7110_write(sd, 0x0E, enable ? 0x18 : 0x80); in saa7110_s_stream()
313 v4l2_dbg(1, debug, sd, "YUV %s\n", enable ? "on" : "off"); in saa7110_s_stream()
320 struct v4l2_subdev *sd = to_sd(ctrl); in saa7110_s_ctrl() local
322 switch (ctrl->id) { in saa7110_s_ctrl()
324 saa7110_write(sd, 0x19, ctrl->val); in saa7110_s_ctrl()
327 saa7110_write(sd, 0x13, ctrl->val); in saa7110_s_ctrl()
330 saa7110_write(sd, 0x12, ctrl->val); in saa7110_s_ctrl()
333 saa7110_write(sd, 0x07, ctrl->val); in saa7110_s_ctrl()
336 return -EINVAL; in saa7110_s_ctrl()
341 /* ----------------------------------------------------------------------- */
359 /* ----------------------------------------------------------------------- */
364 struct v4l2_subdev *sd; in saa7110_probe() local
368 if (!i2c_check_functionality(client->adapter, in saa7110_probe()
370 return -ENODEV; in saa7110_probe()
373 client->addr << 1, client->adapter->name); in saa7110_probe()
375 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); in saa7110_probe()
377 return -ENOMEM; in saa7110_probe()
378 sd = &decoder->sd; in saa7110_probe()
379 v4l2_i2c_subdev_init(sd, client, &saa7110_ops); in saa7110_probe()
380 decoder->norm = V4L2_STD_PAL; in saa7110_probe()
381 decoder->input = 0; in saa7110_probe()
382 decoder->enable = 1; in saa7110_probe()
383 v4l2_ctrl_handler_init(&decoder->hdl, 2); in saa7110_probe()
384 v4l2_ctrl_new_std(&decoder->hdl, &saa7110_ctrl_ops, in saa7110_probe()
385 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); in saa7110_probe()
386 v4l2_ctrl_new_std(&decoder->hdl, &saa7110_ctrl_ops, in saa7110_probe()
387 V4L2_CID_CONTRAST, 0, 127, 1, 64); in saa7110_probe()
388 v4l2_ctrl_new_std(&decoder->hdl, &saa7110_ctrl_ops, in saa7110_probe()
389 V4L2_CID_SATURATION, 0, 127, 1, 64); in saa7110_probe()
390 v4l2_ctrl_new_std(&decoder->hdl, &saa7110_ctrl_ops, in saa7110_probe()
391 V4L2_CID_HUE, -128, 127, 1, 0); in saa7110_probe()
392 sd->ctrl_handler = &decoder->hdl; in saa7110_probe()
393 if (decoder->hdl.error) { in saa7110_probe()
394 int err = decoder->hdl.error; in saa7110_probe()
396 v4l2_ctrl_handler_free(&decoder->hdl); in saa7110_probe()
399 v4l2_ctrl_handler_setup(&decoder->hdl); in saa7110_probe()
401 init_waitqueue_head(&decoder->wq); in saa7110_probe()
403 rv = saa7110_write_block(sd, initseq, sizeof(initseq)); in saa7110_probe()
405 v4l2_dbg(1, debug, sd, "init status %d\n", rv); in saa7110_probe()
408 saa7110_write(sd, 0x21, 0x10); in saa7110_probe()
409 saa7110_write(sd, 0x0e, 0x18); in saa7110_probe()
410 saa7110_write(sd, 0x0D, 0x04); in saa7110_probe()
411 ver = saa7110_read(sd); in saa7110_probe()
412 saa7110_write(sd, 0x0D, 0x06); in saa7110_probe()
414 status = saa7110_read(sd); in saa7110_probe()
415 v4l2_dbg(1, debug, sd, "version %x, status=0x%02x\n", in saa7110_probe()
417 saa7110_write(sd, 0x0D, 0x86); in saa7110_probe()
418 saa7110_write(sd, 0x0F, 0x10); in saa7110_probe()
419 saa7110_write(sd, 0x11, 0x59); in saa7110_probe()
420 /*saa7110_write(sd, 0x2E, 0x9A);*/ in saa7110_probe()
423 /*saa7110_selmux(sd,0);*/ in saa7110_probe()
424 /*determine_norm(sd);*/ in saa7110_probe()
432 struct v4l2_subdev *sd = i2c_get_clientdata(client); in saa7110_remove() local
433 struct saa7110 *decoder = to_saa7110(sd); in saa7110_remove()
435 v4l2_device_unregister_subdev(sd); in saa7110_remove()
436 v4l2_ctrl_handler_free(&decoder->hdl); in saa7110_remove()
439 /* ----------------------------------------------------------------------- */