Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2006 Micronas USA Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License (Version 2) as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 15 | #include <linux/delay.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/unistd.h> |
| 19 | #include <linux/time.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/vmalloc.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/i2c.h> |
| 24 | #include <linux/firmware.h> |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 26 | #include <linux/uaccess.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Ross Cohen | df20d69 | 2008-09-29 22:36:24 -0400 | [diff] [blame] | 28 | #include <linux/videodev2.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 29 | #include <media/tuner.h> |
| 30 | #include <media/v4l2-common.h> |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 31 | #include <media/v4l2-event.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 32 | |
| 33 | #include "go7007-priv.h" |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Wait for an interrupt to be delivered from the GO7007SB and return |
| 37 | * the associated value and data. |
| 38 | * |
| 39 | * Must be called with the hw_lock held. |
| 40 | */ |
| 41 | int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data) |
| 42 | { |
| 43 | go->interrupt_available = 0; |
| 44 | go->hpi_ops->read_interrupt(go); |
| 45 | if (wait_event_timeout(go->interrupt_waitq, |
| 46 | go->interrupt_available, 5*HZ) < 0) { |
Pete Eberlein | 0b398f4 | 2009-11-16 15:07:42 -0300 | [diff] [blame] | 47 | v4l2_err(&go->v4l2_dev, "timeout waiting for read interrupt\n"); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 48 | return -1; |
| 49 | } |
| 50 | if (!go->interrupt_available) |
| 51 | return -1; |
| 52 | go->interrupt_available = 0; |
| 53 | *value = go->interrupt_value & 0xfffe; |
| 54 | *data = go->interrupt_data; |
| 55 | return 0; |
| 56 | } |
| 57 | EXPORT_SYMBOL(go7007_read_interrupt); |
| 58 | |
| 59 | /* |
| 60 | * Read a register/address on the GO7007SB. |
| 61 | * |
| 62 | * Must be called with the hw_lock held. |
| 63 | */ |
| 64 | int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data) |
| 65 | { |
| 66 | int count = 100; |
| 67 | u16 value; |
| 68 | |
| 69 | if (go7007_write_interrupt(go, 0x0010, addr) < 0) |
| 70 | return -EIO; |
| 71 | while (count-- > 0) { |
| 72 | if (go7007_read_interrupt(go, &value, data) == 0 && |
| 73 | value == 0xa000) |
| 74 | return 0; |
| 75 | } |
| 76 | return -EIO; |
| 77 | } |
| 78 | EXPORT_SYMBOL(go7007_read_addr); |
| 79 | |
| 80 | /* |
| 81 | * Send the boot firmware to the encoder, which just wakes it up and lets |
| 82 | * us talk to the GPIO pins and on-board I2C adapter. |
| 83 | * |
| 84 | * Must be called with the hw_lock held. |
| 85 | */ |
| 86 | static int go7007_load_encoder(struct go7007 *go) |
| 87 | { |
| 88 | const struct firmware *fw_entry; |
Hans Verkuil | 0ee3d4d | 2013-03-11 06:45:14 -0300 | [diff] [blame] | 89 | char fw_name[] = "go7007/go7007fw.bin"; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 90 | void *bounce; |
| 91 | int fw_len, rv = 0; |
| 92 | u16 intr_val, intr_data; |
| 93 | |
Hans Verkuil | 95ef394 | 2013-03-09 10:37:52 -0300 | [diff] [blame] | 94 | if (go->boot_fw == NULL) { |
| 95 | if (request_firmware(&fw_entry, fw_name, go->dev)) { |
| 96 | v4l2_err(go, "unable to load firmware from file \"%s\"\n", fw_name); |
| 97 | return -1; |
| 98 | } |
| 99 | if (fw_entry->size < 16 || memcmp(fw_entry->data, "WISGO7007FW", 11)) { |
| 100 | v4l2_err(go, "file \"%s\" does not appear to be go7007 firmware\n", fw_name); |
| 101 | release_firmware(fw_entry); |
| 102 | return -1; |
| 103 | } |
| 104 | fw_len = fw_entry->size - 16; |
| 105 | bounce = kmemdup(fw_entry->data + 16, fw_len, GFP_KERNEL); |
| 106 | if (bounce == NULL) { |
| 107 | v4l2_err(go, "unable to allocate %d bytes for firmware transfer\n", fw_len); |
| 108 | release_firmware(fw_entry); |
| 109 | return -1; |
| 110 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 111 | release_firmware(fw_entry); |
Hans Verkuil | 95ef394 | 2013-03-09 10:37:52 -0300 | [diff] [blame] | 112 | go->boot_fw_len = fw_len; |
| 113 | go->boot_fw = bounce; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 114 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 115 | if (go7007_interface_reset(go) < 0 || |
Hans Verkuil | 95ef394 | 2013-03-09 10:37:52 -0300 | [diff] [blame] | 116 | go7007_send_firmware(go, go->boot_fw, go->boot_fw_len) < 0 || |
| 117 | go7007_read_interrupt(go, &intr_val, &intr_data) < 0 || |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 118 | (intr_val & ~0x1) != 0x5a5a) { |
Pete Eberlein | 6247407 | 2009-09-18 23:06:15 -0300 | [diff] [blame] | 119 | v4l2_err(go, "error transferring firmware\n"); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 120 | rv = -1; |
| 121 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 122 | return rv; |
| 123 | } |
| 124 | |
Hans Verkuil | 0ee3d4d | 2013-03-11 06:45:14 -0300 | [diff] [blame] | 125 | MODULE_FIRMWARE("go7007/go7007fw.bin"); |
Ben Hutchings | 5d929a7 | 2010-01-13 23:36:09 +0000 | [diff] [blame] | 126 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 127 | /* |
| 128 | * Boot the encoder and register the I2C adapter if requested. Do the |
| 129 | * minimum initialization necessary, since the board-specific code may |
| 130 | * still need to probe the board ID. |
| 131 | * |
| 132 | * Must NOT be called with the hw_lock held. |
| 133 | */ |
| 134 | int go7007_boot_encoder(struct go7007 *go, int init_i2c) |
| 135 | { |
| 136 | int ret; |
| 137 | |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 138 | mutex_lock(&go->hw_lock); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 139 | ret = go7007_load_encoder(go); |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 140 | mutex_unlock(&go->hw_lock); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 141 | if (ret < 0) |
| 142 | return -1; |
| 143 | if (!init_i2c) |
| 144 | return 0; |
| 145 | if (go7007_i2c_init(go) < 0) |
| 146 | return -1; |
| 147 | go->i2c_adapter_online = 1; |
| 148 | return 0; |
| 149 | } |
| 150 | EXPORT_SYMBOL(go7007_boot_encoder); |
| 151 | |
| 152 | /* |
| 153 | * Configure any hardware-related registers in the GO7007, such as GPIO |
| 154 | * pins and bus parameters, which are board-specific. This assumes |
| 155 | * the boot firmware has already been downloaded. |
| 156 | * |
| 157 | * Must be called with the hw_lock held. |
| 158 | */ |
| 159 | static int go7007_init_encoder(struct go7007 *go) |
| 160 | { |
| 161 | if (go->board_info->audio_flags & GO7007_AUDIO_I2S_MASTER) { |
| 162 | go7007_write_addr(go, 0x1000, 0x0811); |
| 163 | go7007_write_addr(go, 0x1000, 0x0c11); |
| 164 | } |
Hans Verkuil | 1f1aed2 | 2013-03-17 10:15:03 -0300 | [diff] [blame] | 165 | switch (go->board_id) { |
| 166 | case GO7007_BOARDID_MATRIX_REV: |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 167 | /* Set GPIO pin 0 to be an output (audio clock control) */ |
| 168 | go7007_write_addr(go, 0x3c82, 0x0001); |
| 169 | go7007_write_addr(go, 0x3c80, 0x00fe); |
Hans Verkuil | 1f1aed2 | 2013-03-17 10:15:03 -0300 | [diff] [blame] | 170 | break; |
| 171 | case GO7007_BOARDID_ADLINK_MPG24: |
Volokh Konstantin | d18b6ac | 2013-01-16 09:00:50 -0300 | [diff] [blame] | 172 | /* set GPIO5 to be an output, currently low */ |
| 173 | go7007_write_addr(go, 0x3c82, 0x0000); |
| 174 | go7007_write_addr(go, 0x3c80, 0x00df); |
Hans Verkuil | 1f1aed2 | 2013-03-17 10:15:03 -0300 | [diff] [blame] | 175 | break; |
| 176 | case GO7007_BOARDID_ADS_USBAV_709: |
| 177 | /* GPIO pin 0: audio clock control */ |
| 178 | /* pin 2: TW9906 reset */ |
| 179 | /* pin 3: capture LED */ |
| 180 | go7007_write_addr(go, 0x3c82, 0x000d); |
| 181 | go7007_write_addr(go, 0x3c80, 0x00f2); |
| 182 | break; |
Volokh Konstantin | d18b6ac | 2013-01-16 09:00:50 -0300 | [diff] [blame] | 183 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Send the boot firmware to the GO7007 and configure the registers. This |
| 189 | * is the only way to stop the encoder once it has started streaming video. |
| 190 | * |
| 191 | * Must be called with the hw_lock held. |
| 192 | */ |
| 193 | int go7007_reset_encoder(struct go7007 *go) |
| 194 | { |
| 195 | if (go7007_load_encoder(go) < 0) |
| 196 | return -1; |
| 197 | return go7007_init_encoder(go); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Attempt to instantiate an I2C client by ID, probably loading a module. |
| 202 | */ |
Volokh Konstantin | dcafb6d | 2013-03-09 08:48:25 -0300 | [diff] [blame] | 203 | static int init_i2c_module(struct i2c_adapter *adapter, const struct go_i2c *const i2c) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 204 | { |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 205 | struct go7007 *go = i2c_get_adapdata(adapter); |
| 206 | struct v4l2_device *v4l2_dev = &go->v4l2_dev; |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 207 | struct v4l2_subdev *sd; |
Volokh Konstantin | dcafb6d | 2013-03-09 08:48:25 -0300 | [diff] [blame] | 208 | struct i2c_board_info info; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 209 | |
Volokh Konstantin | dcafb6d | 2013-03-09 08:48:25 -0300 | [diff] [blame] | 210 | memset(&info, 0, sizeof(info)); |
| 211 | strlcpy(info.type, i2c->type, sizeof(info.type)); |
| 212 | info.addr = i2c->addr; |
| 213 | info.flags = i2c->flags; |
| 214 | |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 215 | sd = v4l2_i2c_new_subdev_board(v4l2_dev, adapter, &info, NULL); |
| 216 | if (sd) { |
| 217 | if (i2c->is_video) |
| 218 | go->sd_video = sd; |
| 219 | if (i2c->is_audio) |
| 220 | go->sd_audio = sd; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 221 | return 0; |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 222 | } |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 223 | |
Hans Verkuil | 9707cb5 | 2014-07-17 20:40:20 -0300 | [diff] [blame] | 224 | pr_info("go7007: probing for module i2c:%s failed\n", i2c->type); |
Volokh Konstantin | dcafb6d | 2013-03-09 08:48:25 -0300 | [diff] [blame] | 225 | return -EINVAL; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
Hans Verkuil | d5d3a7c | 2013-03-11 04:48:30 -0300 | [diff] [blame] | 229 | * Detach and unregister the encoder. The go7007 struct won't be freed |
| 230 | * until v4l2 finishes releasing its resources and all associated fds are |
| 231 | * closed by applications. |
| 232 | */ |
| 233 | static void go7007_remove(struct v4l2_device *v4l2_dev) |
| 234 | { |
| 235 | struct go7007 *go = container_of(v4l2_dev, struct go7007, v4l2_dev); |
| 236 | |
| 237 | v4l2_device_unregister(v4l2_dev); |
| 238 | if (go->hpi_ops->release) |
| 239 | go->hpi_ops->release(go); |
| 240 | if (go->i2c_adapter_online) { |
Linus Torvalds | 99bece7 | 2013-05-02 14:38:53 -0700 | [diff] [blame] | 241 | i2c_del_adapter(&go->i2c_adapter); |
| 242 | go->i2c_adapter_online = 0; |
Hans Verkuil | d5d3a7c | 2013-03-11 04:48:30 -0300 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | kfree(go->boot_fw); |
| 246 | go7007_v4l2_remove(go); |
| 247 | kfree(go); |
| 248 | } |
| 249 | |
| 250 | /* |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 251 | * Finalize the GO7007 hardware setup, register the on-board I2C adapter |
| 252 | * (if used on this board), load the I2C client driver for the sensor |
| 253 | * (SAA7115 or whatever) and other devices, and register the ALSA and V4L2 |
| 254 | * interfaces. |
| 255 | * |
| 256 | * Must NOT be called with the hw_lock held. |
| 257 | */ |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 258 | int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 259 | { |
| 260 | int i, ret; |
| 261 | |
YAMANE Toshiaki | 6d56950 | 2012-11-04 16:40:22 -0300 | [diff] [blame] | 262 | dev_info(go->dev, "go7007: registering new %s\n", go->name); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 263 | |
Hans Verkuil | d5d3a7c | 2013-03-11 04:48:30 -0300 | [diff] [blame] | 264 | go->v4l2_dev.release = go7007_remove; |
| 265 | ret = v4l2_device_register(go->dev, &go->v4l2_dev); |
| 266 | if (ret < 0) |
| 267 | return ret; |
| 268 | |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 269 | mutex_lock(&go->hw_lock); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 270 | ret = go7007_init_encoder(go); |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 271 | mutex_unlock(&go->hw_lock); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 272 | if (ret < 0) |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 273 | return ret; |
| 274 | |
| 275 | ret = go7007_v4l2_ctrl_init(go); |
| 276 | if (ret < 0) |
| 277 | return ret; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 278 | |
| 279 | if (!go->i2c_adapter_online && |
| 280 | go->board_info->flags & GO7007_BOARD_USE_ONBOARD_I2C) { |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 281 | ret = go7007_i2c_init(go); |
| 282 | if (ret < 0) |
| 283 | return ret; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 284 | go->i2c_adapter_online = 1; |
| 285 | } |
| 286 | if (go->i2c_adapter_online) { |
Hans Verkuil | 1f1aed2 | 2013-03-17 10:15:03 -0300 | [diff] [blame] | 287 | if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) { |
| 288 | /* Reset the TW9906 */ |
| 289 | go7007_write_addr(go, 0x3c82, 0x0009); |
| 290 | msleep(50); |
| 291 | go7007_write_addr(go, 0x3c82, 0x000d); |
| 292 | } |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 293 | for (i = 0; i < num_i2c_devs; ++i) |
Volokh Konstantin | dcafb6d | 2013-03-09 08:48:25 -0300 | [diff] [blame] | 294 | init_i2c_module(&go->i2c_adapter, &go->board_info->i2c_devs[i]); |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 295 | |
| 296 | if (go->tuner_type >= 0) { |
| 297 | struct tuner_setup setup = { |
| 298 | .addr = ADDR_UNSET, |
| 299 | .type = go->tuner_type, |
| 300 | .mode_mask = T_ANALOG_TV, |
| 301 | }; |
| 302 | |
| 303 | v4l2_device_call_all(&go->v4l2_dev, 0, tuner, |
| 304 | s_type_addr, &setup); |
| 305 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 306 | if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 307 | v4l2_subdev_call(go->sd_video, video, s_routing, |
| 308 | 0, 0, go->channel_number + 1); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 309 | } |
Hans Verkuil | d5d3a7c | 2013-03-11 04:48:30 -0300 | [diff] [blame] | 310 | |
| 311 | ret = go7007_v4l2_init(go); |
| 312 | if (ret < 0) |
| 313 | return ret; |
| 314 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 315 | if (go->board_info->flags & GO7007_BOARD_HAS_AUDIO) { |
| 316 | go->audio_enabled = 1; |
| 317 | go7007_snd_init(go); |
| 318 | } |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 319 | return 0; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 320 | } |
| 321 | EXPORT_SYMBOL(go7007_register_encoder); |
| 322 | |
| 323 | /* |
| 324 | * Send the encode firmware to the encoder, which will cause it |
| 325 | * to immediately start delivering the video and audio streams. |
| 326 | * |
| 327 | * Must be called with the hw_lock held. |
| 328 | */ |
| 329 | int go7007_start_encoder(struct go7007 *go) |
| 330 | { |
| 331 | u8 *fw; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 332 | int fw_len, rv = 0, i, x, y; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 333 | u16 intr_val, intr_data; |
| 334 | |
| 335 | go->modet_enable = 0; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 336 | for (i = 0; i < 4; i++) |
| 337 | go->modet[i].enable = 0; |
| 338 | |
| 339 | switch (v4l2_ctrl_g_ctrl(go->modet_mode)) { |
| 340 | case V4L2_DETECT_MD_MODE_GLOBAL: |
| 341 | memset(go->modet_map, 0, sizeof(go->modet_map)); |
| 342 | go->modet[0].enable = 1; |
| 343 | go->modet_enable = 1; |
| 344 | break; |
| 345 | case V4L2_DETECT_MD_MODE_REGION_GRID: |
| 346 | for (y = 0; y < go->height / 16; y++) { |
| 347 | for (x = 0; x < go->width / 16; x++) { |
| 348 | int idx = y * go->width / 16 + x; |
| 349 | |
| 350 | go->modet[go->modet_map[idx]].enable = 1; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 351 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 352 | } |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 353 | go->modet_enable = 1; |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | if (go->dvd_mode) |
| 358 | go->modet_enable = 0; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 359 | |
| 360 | if (go7007_construct_fw_image(go, &fw, &fw_len) < 0) |
| 361 | return -1; |
| 362 | |
| 363 | if (go7007_send_firmware(go, fw, fw_len) < 0 || |
| 364 | go7007_read_interrupt(go, &intr_val, &intr_data) < 0) { |
Pete Eberlein | 0b398f4 | 2009-11-16 15:07:42 -0300 | [diff] [blame] | 365 | v4l2_err(&go->v4l2_dev, "error transferring firmware\n"); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 366 | rv = -1; |
| 367 | goto start_error; |
| 368 | } |
| 369 | |
| 370 | go->state = STATE_DATA; |
| 371 | go->parse_length = 0; |
| 372 | go->seen_frame = 0; |
| 373 | if (go7007_stream_start(go) < 0) { |
Pete Eberlein | 0b398f4 | 2009-11-16 15:07:42 -0300 | [diff] [blame] | 374 | v4l2_err(&go->v4l2_dev, "error starting stream transfer\n"); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 375 | rv = -1; |
| 376 | goto start_error; |
| 377 | } |
| 378 | |
| 379 | start_error: |
| 380 | kfree(fw); |
| 381 | return rv; |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Store a byte in the current video buffer, if there is one. |
| 386 | */ |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 387 | static inline void store_byte(struct go7007_buffer *vb, u8 byte) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 388 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 389 | if (vb && vb->vb.vb2_buf.planes[0].bytesused < GO7007_BUF_SIZE) { |
| 390 | u8 *ptr = vb2_plane_vaddr(&vb->vb.vb2_buf, 0); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 391 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 392 | ptr[vb->vb.vb2_buf.planes[0].bytesused++] = byte; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 396 | static void go7007_set_motion_regions(struct go7007 *go, struct go7007_buffer *vb, |
| 397 | u32 motion_regions) |
| 398 | { |
| 399 | if (motion_regions != go->modet_event_status) { |
| 400 | struct v4l2_event ev = { |
| 401 | .type = V4L2_EVENT_MOTION_DET, |
| 402 | .u.motion_det = { |
| 403 | .flags = V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ, |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 404 | .frame_sequence = vb->vb.sequence, |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 405 | .region_mask = motion_regions, |
| 406 | }, |
| 407 | }; |
| 408 | |
| 409 | v4l2_event_queue(&go->vdev, &ev); |
| 410 | go->modet_event_status = motion_regions; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Determine regions with motion and send a motion detection event |
| 416 | * in case of changes. |
| 417 | */ |
| 418 | static void go7007_motion_regions(struct go7007 *go, struct go7007_buffer *vb) |
| 419 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 420 | u32 *bytesused = &vb->vb.vb2_buf.planes[0].bytesused; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 421 | unsigned motion[4] = { 0, 0, 0, 0 }; |
| 422 | u32 motion_regions = 0; |
| 423 | unsigned stride = (go->width + 7) >> 3; |
| 424 | unsigned x, y; |
| 425 | int i; |
| 426 | |
| 427 | for (i = 0; i < 216; ++i) |
| 428 | store_byte(vb, go->active_map[i]); |
| 429 | for (y = 0; y < go->height / 16; y++) { |
| 430 | for (x = 0; x < go->width / 16; x++) { |
| 431 | if (!(go->active_map[y * stride + (x >> 3)] & (1 << (x & 7)))) |
| 432 | continue; |
| 433 | motion[go->modet_map[y * (go->width / 16) + x]]++; |
| 434 | } |
| 435 | } |
| 436 | motion_regions = ((motion[0] > 0) << 0) | |
| 437 | ((motion[1] > 0) << 1) | |
| 438 | ((motion[2] > 0) << 2) | |
| 439 | ((motion[3] > 0) << 3); |
| 440 | *bytesused -= 216; |
| 441 | go7007_set_motion_regions(go, vb, motion_regions); |
| 442 | } |
| 443 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 444 | /* |
| 445 | * Deliver the last video buffer and get a new one to start writing to. |
| 446 | */ |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 447 | static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buffer *vb) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 448 | { |
Mauro Carvalho Chehab | 747598d | 2015-04-28 17:09:23 -0300 | [diff] [blame] | 449 | u32 *bytesused; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 450 | struct go7007_buffer *vb_tmp = NULL; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 451 | |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 452 | if (vb == NULL) { |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 453 | spin_lock(&go->spinlock); |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 454 | if (!list_empty(&go->vidq_active)) |
| 455 | vb = go->active_buf = |
| 456 | list_first_entry(&go->vidq_active, struct go7007_buffer, list); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 457 | spin_unlock(&go->spinlock); |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 458 | go->next_seq++; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 459 | return vb; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 460 | } |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 461 | bytesused = &vb->vb.vb2_buf.planes[0].bytesused; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 462 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 463 | vb->vb.sequence = go->next_seq++; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 464 | if (vb->modet_active && *bytesused + 216 < GO7007_BUF_SIZE) |
| 465 | go7007_motion_regions(go, vb); |
| 466 | else |
| 467 | go7007_set_motion_regions(go, vb, 0); |
| 468 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 469 | v4l2_get_timestamp(&vb->vb.timestamp); |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 470 | vb_tmp = vb; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 471 | spin_lock(&go->spinlock); |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 472 | list_del(&vb->list); |
| 473 | if (list_empty(&go->vidq_active)) |
| 474 | vb = NULL; |
| 475 | else |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 476 | vb = list_first_entry(&go->vidq_active, |
| 477 | struct go7007_buffer, list); |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 478 | go->active_buf = vb; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 479 | spin_unlock(&go->spinlock); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 480 | vb2_buffer_done(&vb_tmp->vb.vb2_buf, VB2_BUF_STATE_DONE); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 481 | return vb; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void write_bitmap_word(struct go7007 *go) |
| 485 | { |
| 486 | int x, y, i, stride = ((go->width >> 4) + 7) >> 3; |
| 487 | |
| 488 | for (i = 0; i < 16; ++i) { |
| 489 | y = (((go->parse_length - 1) << 3) + i) / (go->width >> 4); |
| 490 | x = (((go->parse_length - 1) << 3) + i) % (go->width >> 4); |
Pete Eberlein | a716e9d | 2010-09-23 14:43:41 -0300 | [diff] [blame] | 491 | if (stride * y + (x >> 3) < sizeof(go->active_map)) |
| 492 | go->active_map[stride * y + (x >> 3)] |= |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 493 | (go->modet_word & 1) << (x & 0x7); |
| 494 | go->modet_word >>= 1; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | * Parse a chunk of the video stream into frames. The frames are not |
| 500 | * delimited by the hardware, so we have to parse the frame boundaries |
| 501 | * based on the type of video stream we're receiving. |
| 502 | */ |
| 503 | void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length) |
| 504 | { |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 505 | struct go7007_buffer *vb = go->active_buf; |
Hans Verkuil | ac41fa2 | 2013-03-17 10:11:32 -0300 | [diff] [blame] | 506 | int i, seq_start_code = -1, gop_start_code = -1, frame_start_code = -1; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 507 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 508 | switch (go->format) { |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 509 | case V4L2_PIX_FMT_MPEG4: |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 510 | seq_start_code = 0xB0; |
Hans Verkuil | ac41fa2 | 2013-03-17 10:11:32 -0300 | [diff] [blame] | 511 | gop_start_code = 0xB3; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 512 | frame_start_code = 0xB6; |
| 513 | break; |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 514 | case V4L2_PIX_FMT_MPEG1: |
| 515 | case V4L2_PIX_FMT_MPEG2: |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 516 | seq_start_code = 0xB3; |
Hans Verkuil | ac41fa2 | 2013-03-17 10:11:32 -0300 | [diff] [blame] | 517 | gop_start_code = 0xB8; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 518 | frame_start_code = 0x00; |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | for (i = 0; i < length; ++i) { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 523 | if (vb && vb->vb.vb2_buf.planes[0].bytesused >= |
| 524 | GO7007_BUF_SIZE - 3) { |
Pete Eberlein | 0b398f4 | 2009-11-16 15:07:42 -0300 | [diff] [blame] | 525 | v4l2_info(&go->v4l2_dev, "dropping oversized frame\n"); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 526 | vb->vb.vb2_buf.planes[0].bytesused = 0; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 527 | vb->frame_offset = 0; |
| 528 | vb->modet_active = 0; |
| 529 | vb = go->active_buf = NULL; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | switch (go->state) { |
| 533 | case STATE_DATA: |
| 534 | switch (buf[i]) { |
| 535 | case 0x00: |
| 536 | go->state = STATE_00; |
| 537 | break; |
| 538 | case 0xFF: |
| 539 | go->state = STATE_FF; |
| 540 | break; |
| 541 | default: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 542 | store_byte(vb, buf[i]); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 543 | break; |
| 544 | } |
| 545 | break; |
| 546 | case STATE_00: |
| 547 | switch (buf[i]) { |
| 548 | case 0x00: |
| 549 | go->state = STATE_00_00; |
| 550 | break; |
| 551 | case 0xFF: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 552 | store_byte(vb, 0x00); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 553 | go->state = STATE_FF; |
| 554 | break; |
| 555 | default: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 556 | store_byte(vb, 0x00); |
| 557 | store_byte(vb, buf[i]); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 558 | go->state = STATE_DATA; |
| 559 | break; |
| 560 | } |
| 561 | break; |
| 562 | case STATE_00_00: |
| 563 | switch (buf[i]) { |
| 564 | case 0x00: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 565 | store_byte(vb, 0x00); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 566 | /* go->state remains STATE_00_00 */ |
| 567 | break; |
| 568 | case 0x01: |
| 569 | go->state = STATE_00_00_01; |
| 570 | break; |
| 571 | case 0xFF: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 572 | store_byte(vb, 0x00); |
| 573 | store_byte(vb, 0x00); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 574 | go->state = STATE_FF; |
| 575 | break; |
| 576 | default: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 577 | store_byte(vb, 0x00); |
| 578 | store_byte(vb, 0x00); |
| 579 | store_byte(vb, buf[i]); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 580 | go->state = STATE_DATA; |
| 581 | break; |
| 582 | } |
| 583 | break; |
| 584 | case STATE_00_00_01: |
Pete Eberlein | a716e9d | 2010-09-23 14:43:41 -0300 | [diff] [blame] | 585 | if (buf[i] == 0xF8 && go->modet_enable == 0) { |
| 586 | /* MODET start code, but MODET not enabled */ |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 587 | store_byte(vb, 0x00); |
| 588 | store_byte(vb, 0x00); |
| 589 | store_byte(vb, 0x01); |
| 590 | store_byte(vb, 0xF8); |
Pete Eberlein | a716e9d | 2010-09-23 14:43:41 -0300 | [diff] [blame] | 591 | go->state = STATE_DATA; |
| 592 | break; |
| 593 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 594 | /* If this is the start of a new MPEG frame, |
| 595 | * get a new buffer */ |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 596 | if ((go->format == V4L2_PIX_FMT_MPEG1 || |
| 597 | go->format == V4L2_PIX_FMT_MPEG2 || |
| 598 | go->format == V4L2_PIX_FMT_MPEG4) && |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 599 | (buf[i] == seq_start_code || |
Hans Verkuil | ac41fa2 | 2013-03-17 10:11:32 -0300 | [diff] [blame] | 600 | buf[i] == gop_start_code || |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 601 | buf[i] == frame_start_code)) { |
| 602 | if (vb == NULL || go->seen_frame) |
| 603 | vb = frame_boundary(go, vb); |
| 604 | go->seen_frame = buf[i] == frame_start_code; |
| 605 | if (vb && go->seen_frame) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame^] | 606 | vb->frame_offset = |
| 607 | vb->vb.vb2_buf.planes[0].bytesused; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 608 | } |
| 609 | /* Handle any special chunk types, or just write the |
| 610 | * start code to the (potentially new) buffer */ |
| 611 | switch (buf[i]) { |
| 612 | case 0xF5: /* timestamp */ |
| 613 | go->parse_length = 12; |
| 614 | go->state = STATE_UNPARSED; |
| 615 | break; |
| 616 | case 0xF6: /* vbi */ |
| 617 | go->state = STATE_VBI_LEN_A; |
| 618 | break; |
| 619 | case 0xF8: /* MD map */ |
| 620 | go->parse_length = 0; |
| 621 | memset(go->active_map, 0, |
| 622 | sizeof(go->active_map)); |
| 623 | go->state = STATE_MODET_MAP; |
| 624 | break; |
| 625 | case 0xFF: /* Potential JPEG start code */ |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 626 | store_byte(vb, 0x00); |
| 627 | store_byte(vb, 0x00); |
| 628 | store_byte(vb, 0x01); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 629 | go->state = STATE_FF; |
| 630 | break; |
| 631 | default: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 632 | store_byte(vb, 0x00); |
| 633 | store_byte(vb, 0x00); |
| 634 | store_byte(vb, 0x01); |
| 635 | store_byte(vb, buf[i]); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 636 | go->state = STATE_DATA; |
| 637 | break; |
| 638 | } |
| 639 | break; |
| 640 | case STATE_FF: |
| 641 | switch (buf[i]) { |
| 642 | case 0x00: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 643 | store_byte(vb, 0xFF); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 644 | go->state = STATE_00; |
| 645 | break; |
| 646 | case 0xFF: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 647 | store_byte(vb, 0xFF); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 648 | /* go->state remains STATE_FF */ |
| 649 | break; |
| 650 | case 0xD8: |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 651 | if (go->format == V4L2_PIX_FMT_MJPEG) |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 652 | vb = frame_boundary(go, vb); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 653 | /* fall through */ |
| 654 | default: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 655 | store_byte(vb, 0xFF); |
| 656 | store_byte(vb, buf[i]); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 657 | go->state = STATE_DATA; |
| 658 | break; |
| 659 | } |
| 660 | break; |
| 661 | case STATE_VBI_LEN_A: |
| 662 | go->parse_length = buf[i] << 8; |
| 663 | go->state = STATE_VBI_LEN_B; |
| 664 | break; |
| 665 | case STATE_VBI_LEN_B: |
| 666 | go->parse_length |= buf[i]; |
| 667 | if (go->parse_length > 0) |
| 668 | go->state = STATE_UNPARSED; |
| 669 | else |
| 670 | go->state = STATE_DATA; |
| 671 | break; |
| 672 | case STATE_MODET_MAP: |
| 673 | if (go->parse_length < 204) { |
| 674 | if (go->parse_length & 1) { |
| 675 | go->modet_word |= buf[i]; |
| 676 | write_bitmap_word(go); |
| 677 | } else |
| 678 | go->modet_word = buf[i] << 8; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 679 | } else if (go->parse_length == 207 && vb) { |
| 680 | vb->modet_active = buf[i]; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 681 | } |
| 682 | if (++go->parse_length == 208) |
| 683 | go->state = STATE_DATA; |
| 684 | break; |
| 685 | case STATE_UNPARSED: |
| 686 | if (--go->parse_length == 0) |
| 687 | go->state = STATE_DATA; |
| 688 | break; |
| 689 | } |
| 690 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 691 | } |
| 692 | EXPORT_SYMBOL(go7007_parse_video_stream); |
| 693 | |
| 694 | /* |
| 695 | * Allocate a new go7007 struct. Used by the hardware-specific probe. |
| 696 | */ |
Hans Verkuil | 0a6ecbb | 2013-03-17 10:56:20 -0300 | [diff] [blame] | 697 | struct go7007 *go7007_alloc(const struct go7007_board_info *board, |
| 698 | struct device *dev) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 699 | { |
| 700 | struct go7007 *go; |
| 701 | int i; |
| 702 | |
Volokh Konstantin | 61a2353 | 2013-01-16 09:00:48 -0300 | [diff] [blame] | 703 | go = kzalloc(sizeof(struct go7007), GFP_KERNEL); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 704 | if (go == NULL) |
| 705 | return NULL; |
| 706 | go->dev = dev; |
| 707 | go->board_info = board; |
| 708 | go->board_id = 0; |
| 709 | go->tuner_type = -1; |
| 710 | go->channel_number = 0; |
| 711 | go->name[0] = 0; |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 712 | mutex_init(&go->hw_lock); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 713 | init_waitqueue_head(&go->frame_waitq); |
| 714 | spin_lock_init(&go->spinlock); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 715 | go->status = STATUS_INIT; |
| 716 | memset(&go->i2c_adapter, 0, sizeof(go->i2c_adapter)); |
| 717 | go->i2c_adapter_online = 0; |
| 718 | go->interrupt_available = 0; |
| 719 | init_waitqueue_head(&go->interrupt_waitq); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 720 | go->input = 0; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 721 | go7007_update_board(go); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 722 | go->encoder_h_halve = 0; |
| 723 | go->encoder_v_halve = 0; |
| 724 | go->encoder_subsample = 0; |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 725 | go->format = V4L2_PIX_FMT_MJPEG; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 726 | go->bitrate = 1500000; |
| 727 | go->fps_scale = 1; |
| 728 | go->pali = 0; |
| 729 | go->aspect_ratio = GO7007_RATIO_1_1; |
| 730 | go->gop_size = 0; |
| 731 | go->ipb = 0; |
| 732 | go->closed_gop = 0; |
| 733 | go->repeat_seqhead = 0; |
| 734 | go->seq_header_enable = 0; |
| 735 | go->gop_header_enable = 0; |
| 736 | go->dvd_mode = 0; |
| 737 | go->interlace_coding = 0; |
| 738 | for (i = 0; i < 4; ++i) |
Joe Perches | 859171c | 2010-11-14 19:04:48 -0800 | [diff] [blame] | 739 | go->modet[i].enable = 0; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 740 | for (i = 0; i < 1624; ++i) |
| 741 | go->modet_map[i] = 0; |
| 742 | go->audio_deliver = NULL; |
| 743 | go->audio_enabled = 0; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 744 | |
| 745 | return go; |
| 746 | } |
| 747 | EXPORT_SYMBOL(go7007_alloc); |
| 748 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 749 | void go7007_update_board(struct go7007 *go) |
| 750 | { |
Hans Verkuil | 0a6ecbb | 2013-03-17 10:56:20 -0300 | [diff] [blame] | 751 | const struct go7007_board_info *board = go->board_info; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 752 | |
| 753 | if (board->sensor_flags & GO7007_SENSOR_TV) { |
| 754 | go->standard = GO7007_STD_NTSC; |
| 755 | go->std = V4L2_STD_NTSC_M; |
| 756 | go->width = 720; |
| 757 | go->height = 480; |
| 758 | go->sensor_framerate = 30000; |
| 759 | } else { |
| 760 | go->standard = GO7007_STD_OTHER; |
| 761 | go->width = board->sensor_width; |
| 762 | go->height = board->sensor_height; |
| 763 | go->sensor_framerate = board->sensor_framerate; |
| 764 | } |
| 765 | go->encoder_v_offset = board->sensor_v_offset; |
| 766 | go->encoder_h_offset = board->sensor_h_offset; |
| 767 | } |
| 768 | EXPORT_SYMBOL(go7007_update_board); |
| 769 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 770 | MODULE_LICENSE("GPL v2"); |