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