Lines Matching full:go

33 int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data)  in go7007_read_interrupt()  argument
35 go->interrupt_available = 0; in go7007_read_interrupt()
36 go->hpi_ops->read_interrupt(go); in go7007_read_interrupt()
37 if (wait_event_timeout(go->interrupt_waitq, in go7007_read_interrupt()
38 go->interrupt_available, 5*HZ) < 0) { in go7007_read_interrupt()
39 v4l2_err(&go->v4l2_dev, "timeout waiting for read interrupt\n"); in go7007_read_interrupt()
42 if (!go->interrupt_available) in go7007_read_interrupt()
44 go->interrupt_available = 0; in go7007_read_interrupt()
45 *value = go->interrupt_value & 0xfffe; in go7007_read_interrupt()
46 *data = go->interrupt_data; in go7007_read_interrupt()
56 int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data) in go7007_read_addr() argument
61 if (go7007_write_interrupt(go, 0x0010, addr) < 0) in go7007_read_addr()
64 if (go7007_read_interrupt(go, &value, data) == 0 && in go7007_read_addr()
78 static int go7007_load_encoder(struct go7007 *go) in go7007_load_encoder() argument
86 if (go->boot_fw == NULL) { in go7007_load_encoder()
87 if (request_firmware(&fw_entry, fw_name, go->dev)) { in go7007_load_encoder()
88 v4l2_err(go, "unable to load firmware from file \"%s\"\n", fw_name); in go7007_load_encoder()
92 v4l2_err(go, "file \"%s\" does not appear to be go7007 firmware\n", fw_name); in go7007_load_encoder()
99 v4l2_err(go, "unable to allocate %d bytes for firmware transfer\n", fw_len); in go7007_load_encoder()
104 go->boot_fw_len = fw_len; in go7007_load_encoder()
105 go->boot_fw = bounce; in go7007_load_encoder()
107 if (go7007_interface_reset(go) < 0 || in go7007_load_encoder()
108 go7007_send_firmware(go, go->boot_fw, go->boot_fw_len) < 0 || in go7007_load_encoder()
109 go7007_read_interrupt(go, &intr_val, &intr_data) < 0 || in go7007_load_encoder()
111 v4l2_err(go, "error transferring firmware\n"); in go7007_load_encoder()
112 kfree(go->boot_fw); in go7007_load_encoder()
113 go->boot_fw = NULL; in go7007_load_encoder()
128 int go7007_boot_encoder(struct go7007 *go, int init_i2c) in go7007_boot_encoder() argument
132 mutex_lock(&go->hw_lock); in go7007_boot_encoder()
133 ret = go7007_load_encoder(go); in go7007_boot_encoder()
134 mutex_unlock(&go->hw_lock); in go7007_boot_encoder()
139 if (go7007_i2c_init(go) < 0) in go7007_boot_encoder()
141 go->i2c_adapter_online = 1; in go7007_boot_encoder()
153 static int go7007_init_encoder(struct go7007 *go) in go7007_init_encoder() argument
155 if (go->board_info->audio_flags & GO7007_AUDIO_I2S_MASTER) { in go7007_init_encoder()
156 go7007_write_addr(go, 0x1000, 0x0811); in go7007_init_encoder()
157 go7007_write_addr(go, 0x1000, 0x0c11); in go7007_init_encoder()
159 switch (go->board_id) { in go7007_init_encoder()
162 go7007_write_addr(go, 0x3c82, 0x0001); in go7007_init_encoder()
163 go7007_write_addr(go, 0x3c80, 0x00fe); in go7007_init_encoder()
167 go7007_write_addr(go, 0x3c82, 0x0000); in go7007_init_encoder()
168 go7007_write_addr(go, 0x3c80, 0x00df); in go7007_init_encoder()
174 go7007_write_addr(go, 0x3c82, 0x000d); in go7007_init_encoder()
175 go7007_write_addr(go, 0x3c80, 0x00f2); in go7007_init_encoder()
187 int go7007_reset_encoder(struct go7007 *go) in go7007_reset_encoder() argument
189 if (go7007_load_encoder(go) < 0) in go7007_reset_encoder()
191 return go7007_init_encoder(go); in go7007_reset_encoder()
199 struct go7007 *go = i2c_get_adapdata(adapter); in init_i2c_module() local
200 struct v4l2_device *v4l2_dev = &go->v4l2_dev; in init_i2c_module()
212 go->sd_video = sd; in init_i2c_module()
214 go->sd_audio = sd; in init_i2c_module()
229 struct go7007 *go = container_of(v4l2_dev, struct go7007, v4l2_dev); in go7007_remove() local
232 if (go->hpi_ops->release) in go7007_remove()
233 go->hpi_ops->release(go); in go7007_remove()
234 if (go->i2c_adapter_online) { in go7007_remove()
235 i2c_del_adapter(&go->i2c_adapter); in go7007_remove()
236 go->i2c_adapter_online = 0; in go7007_remove()
239 kfree(go->boot_fw); in go7007_remove()
240 go7007_v4l2_remove(go); in go7007_remove()
241 kfree(go); in go7007_remove()
252 int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs) in go7007_register_encoder() argument
256 dev_info(go->dev, "go7007: registering new %s\n", go->name); in go7007_register_encoder()
258 go->v4l2_dev.release = go7007_remove; in go7007_register_encoder()
259 ret = v4l2_device_register(go->dev, &go->v4l2_dev); in go7007_register_encoder()
263 mutex_lock(&go->hw_lock); in go7007_register_encoder()
264 ret = go7007_init_encoder(go); in go7007_register_encoder()
265 mutex_unlock(&go->hw_lock); in go7007_register_encoder()
269 ret = go7007_v4l2_ctrl_init(go); in go7007_register_encoder()
273 if (!go->i2c_adapter_online && in go7007_register_encoder()
274 go->board_info->flags & GO7007_BOARD_USE_ONBOARD_I2C) { in go7007_register_encoder()
275 ret = go7007_i2c_init(go); in go7007_register_encoder()
278 go->i2c_adapter_online = 1; in go7007_register_encoder()
280 if (go->i2c_adapter_online) { in go7007_register_encoder()
281 if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) { in go7007_register_encoder()
283 go7007_write_addr(go, 0x3c82, 0x0009); in go7007_register_encoder()
285 go7007_write_addr(go, 0x3c82, 0x000d); in go7007_register_encoder()
288 init_i2c_module(&go->i2c_adapter, &go->board_info->i2c_devs[i]); in go7007_register_encoder()
290 if (go->tuner_type >= 0) { in go7007_register_encoder()
293 .type = go->tuner_type, in go7007_register_encoder()
297 v4l2_device_call_all(&go->v4l2_dev, 0, tuner, in go7007_register_encoder()
300 if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) in go7007_register_encoder()
301 v4l2_subdev_call(go->sd_video, video, s_routing, in go7007_register_encoder()
302 0, 0, go->channel_number + 1); in go7007_register_encoder()
305 ret = go7007_v4l2_init(go); in go7007_register_encoder()
309 if (go->board_info->flags & GO7007_BOARD_HAS_AUDIO) { in go7007_register_encoder()
310 go->audio_enabled = 1; in go7007_register_encoder()
311 go7007_snd_init(go); in go7007_register_encoder()
323 int go7007_start_encoder(struct go7007 *go) in go7007_start_encoder() argument
329 go->modet_enable = 0; in go7007_start_encoder()
331 go->modet[i].enable = 0; in go7007_start_encoder()
333 switch (v4l2_ctrl_g_ctrl(go->modet_mode)) { in go7007_start_encoder()
335 memset(go->modet_map, 0, sizeof(go->modet_map)); in go7007_start_encoder()
336 go->modet[0].enable = 1; in go7007_start_encoder()
337 go->modet_enable = 1; in go7007_start_encoder()
340 for (y = 0; y < go->height / 16; y++) { in go7007_start_encoder()
341 for (x = 0; x < go->width / 16; x++) { in go7007_start_encoder()
342 int idx = y * go->width / 16 + x; in go7007_start_encoder()
344 go->modet[go->modet_map[idx]].enable = 1; in go7007_start_encoder()
347 go->modet_enable = 1; in go7007_start_encoder()
351 if (go->dvd_mode) in go7007_start_encoder()
352 go->modet_enable = 0; in go7007_start_encoder()
354 if (go7007_construct_fw_image(go, &fw, &fw_len) < 0) in go7007_start_encoder()
357 if (go7007_send_firmware(go, fw, fw_len) < 0 || in go7007_start_encoder()
358 go7007_read_interrupt(go, &intr_val, &intr_data) < 0) { in go7007_start_encoder()
359 v4l2_err(&go->v4l2_dev, "error transferring firmware\n"); in go7007_start_encoder()
364 go->state = STATE_DATA; in go7007_start_encoder()
365 go->parse_length = 0; in go7007_start_encoder()
366 go->seen_frame = 0; in go7007_start_encoder()
367 if (go7007_stream_start(go) < 0) { in go7007_start_encoder()
368 v4l2_err(&go->v4l2_dev, "error starting stream transfer\n"); in go7007_start_encoder()
390 static void go7007_set_motion_regions(struct go7007 *go, struct go7007_buffer *vb, in go7007_set_motion_regions() argument
393 if (motion_regions != go->modet_event_status) { in go7007_set_motion_regions()
403 v4l2_event_queue(&go->vdev, &ev); in go7007_set_motion_regions()
404 go->modet_event_status = motion_regions; in go7007_set_motion_regions()
412 static void go7007_motion_regions(struct go7007 *go, struct go7007_buffer *vb) in go7007_motion_regions() argument
417 unsigned stride = (go->width + 7) >> 3; in go7007_motion_regions()
422 store_byte(vb, go->active_map[i]); in go7007_motion_regions()
423 for (y = 0; y < go->height / 16; y++) { in go7007_motion_regions()
424 for (x = 0; x < go->width / 16; x++) { in go7007_motion_regions()
425 if (!(go->active_map[y * stride + (x >> 3)] & (1 << (x & 7)))) in go7007_motion_regions()
427 motion[go->modet_map[y * (go->width / 16) + x]]++; in go7007_motion_regions()
435 go7007_set_motion_regions(go, vb, motion_regions); in go7007_motion_regions()
441 static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buffer *vb) in frame_boundary() argument
448 spin_lock_irqsave(&go->spinlock, flags); in frame_boundary()
449 if (!list_empty(&go->vidq_active)) in frame_boundary()
450 vb = go->active_buf = in frame_boundary()
451 list_first_entry(&go->vidq_active, struct go7007_buffer, list); in frame_boundary()
452 spin_unlock_irqrestore(&go->spinlock, flags); in frame_boundary()
453 go->next_seq++; in frame_boundary()
458 vb->vb.sequence = go->next_seq++; in frame_boundary()
460 go7007_motion_regions(go, vb); in frame_boundary()
462 go7007_set_motion_regions(go, vb, 0); in frame_boundary()
466 spin_lock_irqsave(&go->spinlock, flags); in frame_boundary()
468 if (list_empty(&go->vidq_active)) in frame_boundary()
471 vb = list_first_entry(&go->vidq_active, in frame_boundary()
473 go->active_buf = vb; in frame_boundary()
474 spin_unlock_irqrestore(&go->spinlock, flags); in frame_boundary()
479 static void write_bitmap_word(struct go7007 *go) in write_bitmap_word() argument
481 int x, y, i, stride = ((go->width >> 4) + 7) >> 3; in write_bitmap_word()
484 y = (((go->parse_length - 1) << 3) + i) / (go->width >> 4); in write_bitmap_word()
485 x = (((go->parse_length - 1) << 3) + i) % (go->width >> 4); in write_bitmap_word()
486 if (stride * y + (x >> 3) < sizeof(go->active_map)) in write_bitmap_word()
487 go->active_map[stride * y + (x >> 3)] |= in write_bitmap_word()
488 (go->modet_word & 1) << (x & 0x7); in write_bitmap_word()
489 go->modet_word >>= 1; in write_bitmap_word()
498 void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length) in go7007_parse_video_stream() argument
500 struct go7007_buffer *vb = go->active_buf; in go7007_parse_video_stream()
503 switch (go->format) { in go7007_parse_video_stream()
520 v4l2_info(&go->v4l2_dev, "dropping oversized frame\n"); in go7007_parse_video_stream()
524 vb = go->active_buf = NULL; in go7007_parse_video_stream()
527 switch (go->state) { in go7007_parse_video_stream()
531 go->state = STATE_00; in go7007_parse_video_stream()
534 go->state = STATE_FF; in go7007_parse_video_stream()
544 go->state = STATE_00_00; in go7007_parse_video_stream()
548 go->state = STATE_FF; in go7007_parse_video_stream()
553 go->state = STATE_DATA; in go7007_parse_video_stream()
561 /* go->state remains STATE_00_00 */ in go7007_parse_video_stream()
564 go->state = STATE_00_00_01; in go7007_parse_video_stream()
569 go->state = STATE_FF; in go7007_parse_video_stream()
575 go->state = STATE_DATA; in go7007_parse_video_stream()
580 if (buf[i] == 0xF8 && go->modet_enable == 0) { in go7007_parse_video_stream()
586 go->state = STATE_DATA; in go7007_parse_video_stream()
591 if ((go->format == V4L2_PIX_FMT_MPEG1 || in go7007_parse_video_stream()
592 go->format == V4L2_PIX_FMT_MPEG2 || in go7007_parse_video_stream()
593 go->format == V4L2_PIX_FMT_MPEG4) && in go7007_parse_video_stream()
597 if (vb == NULL || go->seen_frame) in go7007_parse_video_stream()
598 vb = frame_boundary(go, vb); in go7007_parse_video_stream()
599 go->seen_frame = buf[i] == frame_start_code; in go7007_parse_video_stream()
600 if (vb && go->seen_frame) in go7007_parse_video_stream()
608 go->parse_length = 12; in go7007_parse_video_stream()
609 go->state = STATE_UNPARSED; in go7007_parse_video_stream()
612 go->state = STATE_VBI_LEN_A; in go7007_parse_video_stream()
615 go->parse_length = 0; in go7007_parse_video_stream()
616 memset(go->active_map, 0, in go7007_parse_video_stream()
617 sizeof(go->active_map)); in go7007_parse_video_stream()
618 go->state = STATE_MODET_MAP; in go7007_parse_video_stream()
624 go->state = STATE_FF; in go7007_parse_video_stream()
631 go->state = STATE_DATA; in go7007_parse_video_stream()
639 go->state = STATE_00; in go7007_parse_video_stream()
643 /* go->state remains STATE_FF */ in go7007_parse_video_stream()
646 if (go->format == V4L2_PIX_FMT_MJPEG) in go7007_parse_video_stream()
647 vb = frame_boundary(go, vb); in go7007_parse_video_stream()
652 go->state = STATE_DATA; in go7007_parse_video_stream()
657 go->parse_length = buf[i] << 8; in go7007_parse_video_stream()
658 go->state = STATE_VBI_LEN_B; in go7007_parse_video_stream()
661 go->parse_length |= buf[i]; in go7007_parse_video_stream()
662 if (go->parse_length > 0) in go7007_parse_video_stream()
663 go->state = STATE_UNPARSED; in go7007_parse_video_stream()
665 go->state = STATE_DATA; in go7007_parse_video_stream()
668 if (go->parse_length < 204) { in go7007_parse_video_stream()
669 if (go->parse_length & 1) { in go7007_parse_video_stream()
670 go->modet_word |= buf[i]; in go7007_parse_video_stream()
671 write_bitmap_word(go); in go7007_parse_video_stream()
673 go->modet_word = buf[i] << 8; in go7007_parse_video_stream()
674 } else if (go->parse_length == 207 && vb) { in go7007_parse_video_stream()
677 if (++go->parse_length == 208) in go7007_parse_video_stream()
678 go->state = STATE_DATA; in go7007_parse_video_stream()
681 if (--go->parse_length == 0) in go7007_parse_video_stream()
682 go->state = STATE_DATA; in go7007_parse_video_stream()
695 struct go7007 *go; in go7007_alloc() local
697 go = kzalloc(sizeof(struct go7007), GFP_KERNEL); in go7007_alloc()
698 if (go == NULL) in go7007_alloc()
700 go->dev = dev; in go7007_alloc()
701 go->board_info = board; in go7007_alloc()
702 go->tuner_type = -1; in go7007_alloc()
703 mutex_init(&go->hw_lock); in go7007_alloc()
704 init_waitqueue_head(&go->frame_waitq); in go7007_alloc()
705 spin_lock_init(&go->spinlock); in go7007_alloc()
706 go->status = STATUS_INIT; in go7007_alloc()
707 init_waitqueue_head(&go->interrupt_waitq); in go7007_alloc()
708 go7007_update_board(go); in go7007_alloc()
709 go->format = V4L2_PIX_FMT_MJPEG; in go7007_alloc()
710 go->bitrate = 1500000; in go7007_alloc()
711 go->fps_scale = 1; in go7007_alloc()
712 go->aspect_ratio = GO7007_RATIO_1_1; in go7007_alloc()
714 return go; in go7007_alloc()
718 void go7007_update_board(struct go7007 *go) in go7007_update_board() argument
720 const struct go7007_board_info *board = go->board_info; in go7007_update_board()
723 go->standard = GO7007_STD_NTSC; in go7007_update_board()
724 go->std = V4L2_STD_NTSC_M; in go7007_update_board()
725 go->width = 720; in go7007_update_board()
726 go->height = 480; in go7007_update_board()
727 go->sensor_framerate = 30000; in go7007_update_board()
729 go->standard = GO7007_STD_OTHER; in go7007_update_board()
730 go->width = board->sensor_width; in go7007_update_board()
731 go->height = board->sensor_height; in go7007_update_board()
732 go->sensor_framerate = board->sensor_framerate; in go7007_update_board()
734 go->encoder_v_offset = board->sensor_v_offset; in go7007_update_board()
735 go->encoder_h_offset = board->sensor_h_offset; in go7007_update_board()