Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cx18 driver initialization and card probing |
| 3 | * |
| 4 | * Derived from ivtv-driver.c |
| 5 | * |
| 6 | * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame] | 7 | * Copyright (C) 2008 Andy Walls <awalls@radix.net> |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 22 | * 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include "cx18-driver.h" |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 26 | #include "cx18-io.h" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 27 | #include "cx18-version.h" |
| 28 | #include "cx18-cards.h" |
| 29 | #include "cx18-i2c.h" |
| 30 | #include "cx18-irq.h" |
| 31 | #include "cx18-gpio.h" |
| 32 | #include "cx18-firmware.h" |
Andy Walls | 21a278b | 2009-04-15 20:45:10 -0300 | [diff] [blame] | 33 | #include "cx18-queue.h" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 34 | #include "cx18-streams.h" |
| 35 | #include "cx18-av-core.h" |
| 36 | #include "cx18-scb.h" |
| 37 | #include "cx18-mailbox.h" |
| 38 | #include "cx18-ioctl.h" |
| 39 | #include "tuner-xc2028.h" |
| 40 | |
| 41 | #include <media/tveeprom.h> |
| 42 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 43 | /* If you have already X v4l cards, then set this to X. This way |
| 44 | the device numbers stay matched. Example: you have a WinTV card |
| 45 | without radio and a Compro H900 with. Normally this would give a |
| 46 | video1 device together with a radio0 device for the Compro. By |
| 47 | setting this to 1 you ensure that radio0 is now also radio1. */ |
| 48 | int cx18_first_minor; |
| 49 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 50 | /* add your revision and whatnot here */ |
| 51 | static struct pci_device_id cx18_pci_tbl[] __devinitdata = { |
| 52 | {PCI_VENDOR_ID_CX, PCI_DEVICE_ID_CX23418, |
| 53 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 54 | {0,} |
| 55 | }; |
| 56 | |
| 57 | MODULE_DEVICE_TABLE(pci, cx18_pci_tbl); |
| 58 | |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 59 | static atomic_t cx18_instance = ATOMIC_INIT(0); |
| 60 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 61 | /* Parameter declarations */ |
| 62 | static int cardtype[CX18_MAX_CARDS]; |
| 63 | static int tuner[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, |
| 64 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 65 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 66 | -1, -1, -1, -1, -1, -1, -1, -1 }; |
| 67 | static int radio[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, |
| 68 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 69 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 70 | -1, -1, -1, -1, -1, -1, -1, -1 }; |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 71 | static unsigned cardtype_c = 1; |
| 72 | static unsigned tuner_c = 1; |
| 73 | static unsigned radio_c = 1; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 74 | static char pal[] = "--"; |
| 75 | static char secam[] = "--"; |
| 76 | static char ntsc[] = "-"; |
| 77 | |
| 78 | /* Buffers */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 79 | static int enc_ts_buffers = CX18_DEFAULT_ENC_TS_BUFFERS; |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 80 | static int enc_mpg_buffers = CX18_DEFAULT_ENC_MPG_BUFFERS; |
| 81 | static int enc_idx_buffers = CX18_DEFAULT_ENC_IDX_BUFFERS; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 82 | static int enc_yuv_buffers = CX18_DEFAULT_ENC_YUV_BUFFERS; |
| 83 | static int enc_vbi_buffers = CX18_DEFAULT_ENC_VBI_BUFFERS; |
| 84 | static int enc_pcm_buffers = CX18_DEFAULT_ENC_PCM_BUFFERS; |
| 85 | |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 86 | static int enc_ts_bufsize = CX18_DEFAULT_ENC_TS_BUFSIZE; |
| 87 | static int enc_mpg_bufsize = CX18_DEFAULT_ENC_MPG_BUFSIZE; |
| 88 | static int enc_idx_bufsize = CX18_DEFAULT_ENC_IDX_BUFSIZE; |
| 89 | static int enc_yuv_bufsize = CX18_DEFAULT_ENC_YUV_BUFSIZE; |
| 90 | /* VBI bufsize based on standards supported by card tuner for now */ |
| 91 | static int enc_pcm_bufsize = CX18_DEFAULT_ENC_PCM_BUFSIZE; |
| 92 | |
| 93 | static int enc_ts_bufs = -1; |
| 94 | static int enc_mpg_bufs = -1; |
| 95 | static int enc_idx_bufs = -1; |
| 96 | static int enc_yuv_bufs = -1; |
| 97 | static int enc_vbi_bufs = -1; |
| 98 | static int enc_pcm_bufs = -1; |
| 99 | |
| 100 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 101 | static int cx18_pci_latency = 1; |
| 102 | |
Andy Walls | 3f75c61 | 2008-11-16 23:33:41 -0300 | [diff] [blame] | 103 | static int mmio_ndelay; |
| 104 | static int retry_mmio = 1; |
| 105 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 106 | int cx18_debug; |
| 107 | |
| 108 | module_param_array(tuner, int, &tuner_c, 0644); |
| 109 | module_param_array(radio, bool, &radio_c, 0644); |
| 110 | module_param_array(cardtype, int, &cardtype_c, 0644); |
| 111 | module_param_string(pal, pal, sizeof(pal), 0644); |
| 112 | module_param_string(secam, secam, sizeof(secam), 0644); |
| 113 | module_param_string(ntsc, ntsc, sizeof(ntsc), 0644); |
| 114 | module_param_named(debug, cx18_debug, int, 0644); |
Andy Walls | 3f75c61 | 2008-11-16 23:33:41 -0300 | [diff] [blame] | 115 | module_param(mmio_ndelay, int, 0644); |
| 116 | module_param(retry_mmio, int, 0644); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 117 | module_param(cx18_pci_latency, int, 0644); |
| 118 | module_param(cx18_first_minor, int, 0644); |
| 119 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 120 | module_param(enc_ts_buffers, int, 0644); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 121 | module_param(enc_mpg_buffers, int, 0644); |
| 122 | module_param(enc_idx_buffers, int, 0644); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 123 | module_param(enc_yuv_buffers, int, 0644); |
| 124 | module_param(enc_vbi_buffers, int, 0644); |
| 125 | module_param(enc_pcm_buffers, int, 0644); |
| 126 | |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 127 | module_param(enc_ts_bufsize, int, 0644); |
| 128 | module_param(enc_mpg_bufsize, int, 0644); |
| 129 | module_param(enc_idx_bufsize, int, 0644); |
| 130 | module_param(enc_yuv_bufsize, int, 0644); |
| 131 | /* VBI bufsize based on standards supported by card tuner for now */ |
| 132 | module_param(enc_pcm_bufsize, int, 0644); |
| 133 | |
| 134 | module_param(enc_ts_bufs, int, 0644); |
| 135 | module_param(enc_mpg_bufs, int, 0644); |
| 136 | module_param(enc_idx_bufs, int, 0644); |
| 137 | module_param(enc_yuv_bufs, int, 0644); |
| 138 | module_param(enc_vbi_bufs, int, 0644); |
| 139 | module_param(enc_pcm_bufs, int, 0644); |
| 140 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 141 | MODULE_PARM_DESC(tuner, "Tuner type selection,\n" |
| 142 | "\t\t\tsee tuner.h for values"); |
| 143 | MODULE_PARM_DESC(radio, |
| 144 | "Enable or disable the radio. Use only if autodetection\n" |
| 145 | "\t\t\tfails. 0 = disable, 1 = enable"); |
| 146 | MODULE_PARM_DESC(cardtype, |
| 147 | "Only use this option if your card is not detected properly.\n" |
| 148 | "\t\tSpecify card type:\n" |
| 149 | "\t\t\t 1 = Hauppauge HVR 1600 (ESMT memory)\n" |
| 150 | "\t\t\t 2 = Hauppauge HVR 1600 (Samsung memory)\n" |
| 151 | "\t\t\t 3 = Compro VideoMate H900\n" |
| 152 | "\t\t\t 4 = Yuan MPC718\n" |
Sri Deevi | 03c2808 | 2008-06-21 11:06:44 -0300 | [diff] [blame] | 153 | "\t\t\t 5 = Conexant Raptor PAL/SECAM\n" |
Andy Walls | 9eee4fb | 2008-10-04 20:28:40 -0300 | [diff] [blame] | 154 | "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n" |
Andy Walls | 9d5af86 | 2009-06-09 20:37:24 -0300 | [diff] [blame] | 155 | "\t\t\t 7 = Leadtek WinFast PVR2100\n" |
| 156 | "\t\t\t 8 = Leadtek WinFast DVR3100 H\n" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 157 | "\t\t\t 0 = Autodetect (default)\n" |
| 158 | "\t\t\t-1 = Ignore this card\n\t\t"); |
| 159 | MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60"); |
| 160 | MODULE_PARM_DESC(secam, "Set SECAM standard: B, G, H, D, K, L, LC"); |
| 161 | MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K"); |
| 162 | MODULE_PARM_DESC(debug, |
| 163 | "Debug level (bitmask). Default: 0\n" |
| 164 | "\t\t\t 1/0x0001: warning\n" |
| 165 | "\t\t\t 2/0x0002: info\n" |
| 166 | "\t\t\t 4/0x0004: mailbox\n" |
| 167 | "\t\t\t 8/0x0008: dma\n" |
| 168 | "\t\t\t 16/0x0010: ioctl\n" |
| 169 | "\t\t\t 32/0x0020: file\n" |
| 170 | "\t\t\t 64/0x0040: i2c\n" |
| 171 | "\t\t\t128/0x0080: irq\n" |
| 172 | "\t\t\t256/0x0100: high volume\n"); |
| 173 | MODULE_PARM_DESC(cx18_pci_latency, |
| 174 | "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n" |
| 175 | "\t\t\tDefault: Yes"); |
Andy Walls | d267d85 | 2008-09-28 21:46:02 -0300 | [diff] [blame] | 176 | MODULE_PARM_DESC(retry_mmio, |
Andy Walls | 3f75c61 | 2008-11-16 23:33:41 -0300 | [diff] [blame] | 177 | "(Deprecated) MMIO writes are now always checked and retried\n" |
| 178 | "\t\t\tEffectively: 1 [Yes]"); |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame] | 179 | MODULE_PARM_DESC(mmio_ndelay, |
Andy Walls | 3f75c61 | 2008-11-16 23:33:41 -0300 | [diff] [blame] | 180 | "(Deprecated) MMIO accesses are now never purposely delayed\n" |
| 181 | "\t\t\tEffectively: 0 ns"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 182 | MODULE_PARM_DESC(enc_ts_buffers, |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 183 | "Encoder TS buffer memory (MB). (enc_ts_bufs can override)\n" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 184 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFFERS)); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 185 | MODULE_PARM_DESC(enc_ts_bufsize, |
| 186 | "Size of an encoder TS buffer (kB)\n" |
| 187 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFSIZE)); |
| 188 | MODULE_PARM_DESC(enc_ts_bufs, |
| 189 | "Number of encoder TS buffers\n" |
| 190 | "\t\t\tDefault is computed from other enc_ts_* parameters"); |
| 191 | MODULE_PARM_DESC(enc_mpg_buffers, |
| 192 | "Encoder MPG buffer memory (MB). (enc_mpg_bufs can override)\n" |
| 193 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFFERS)); |
| 194 | MODULE_PARM_DESC(enc_mpg_bufsize, |
| 195 | "Size of an encoder MPG buffer (kB)\n" |
| 196 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFSIZE)); |
| 197 | MODULE_PARM_DESC(enc_mpg_bufs, |
| 198 | "Number of encoder MPG buffers\n" |
| 199 | "\t\t\tDefault is computed from other enc_mpg_* parameters"); |
| 200 | MODULE_PARM_DESC(enc_idx_buffers, |
| 201 | "Encoder IDX buffer memory (MB). (enc_idx_bufs can override)\n" |
| 202 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFFERS)); |
| 203 | MODULE_PARM_DESC(enc_idx_bufsize, |
| 204 | "Size of an encoder IDX buffer (kB)\n" |
| 205 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFSIZE)); |
| 206 | MODULE_PARM_DESC(enc_idx_bufs, |
| 207 | "Number of encoder IDX buffers\n" |
| 208 | "\t\t\tDefault is computed from other enc_idx_* parameters"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 209 | MODULE_PARM_DESC(enc_yuv_buffers, |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 210 | "Encoder YUV buffer memory (MB). (enc_yuv_bufs can override)\n" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 211 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_YUV_BUFFERS)); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 212 | MODULE_PARM_DESC(enc_yuv_bufsize, |
| 213 | "Size of an encoder YUV buffer (kB)\n" |
Andy Walls | 22dce18 | 2009-11-09 23:55:30 -0300 | [diff] [blame^] | 214 | "\t\t\tAllowed values are multiples of 33.75 kB rounded up\n" |
| 215 | "\t\t\t(multiples of size required for 32 screen lines)\n" |
| 216 | "\t\t\tDefault: 102"); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 217 | MODULE_PARM_DESC(enc_yuv_bufs, |
| 218 | "Number of encoder YUV buffers\n" |
| 219 | "\t\t\tDefault is computed from other enc_yuv_* parameters"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 220 | MODULE_PARM_DESC(enc_vbi_buffers, |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 221 | "Encoder VBI buffer memory (MB). (enc_vbi_bufs can override)\n" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 222 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_VBI_BUFFERS)); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 223 | MODULE_PARM_DESC(enc_vbi_bufs, |
| 224 | "Number of encoder VBI buffers\n" |
| 225 | "\t\t\tDefault is computed from enc_vbi_buffers & tuner std"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 226 | MODULE_PARM_DESC(enc_pcm_buffers, |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 227 | "Encoder PCM buffer memory (MB). (enc_pcm_bufs can override)\n" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 228 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFFERS)); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 229 | MODULE_PARM_DESC(enc_pcm_bufsize, |
| 230 | "Size of an encoder PCM buffer (kB)\n" |
| 231 | "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFSIZE)); |
| 232 | MODULE_PARM_DESC(enc_pcm_bufs, |
| 233 | "Number of encoder PCM buffers\n" |
| 234 | "\t\t\tDefault is computed from other enc_pcm_* parameters"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 235 | |
Hans Verkuil | 581644d | 2009-06-19 11:54:00 -0300 | [diff] [blame] | 236 | MODULE_PARM_DESC(cx18_first_minor, "Set device node number assigned to first card"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 237 | |
| 238 | MODULE_AUTHOR("Hans Verkuil"); |
| 239 | MODULE_DESCRIPTION("CX23418 driver"); |
| 240 | MODULE_SUPPORTED_DEVICE("CX23418 MPEG2 encoder"); |
| 241 | MODULE_LICENSE("GPL"); |
| 242 | |
| 243 | MODULE_VERSION(CX18_VERSION); |
| 244 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 245 | /* Generic utility functions */ |
| 246 | int cx18_msleep_timeout(unsigned int msecs, int intr) |
| 247 | { |
Andy Walls | 330c6ec | 2008-11-08 14:19:37 -0300 | [diff] [blame] | 248 | long int timeout = msecs_to_jiffies(msecs); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 249 | int sig; |
| 250 | |
| 251 | do { |
| 252 | set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); |
| 253 | timeout = schedule_timeout(timeout); |
| 254 | sig = intr ? signal_pending(current) : 0; |
| 255 | } while (!sig && timeout); |
| 256 | return sig; |
| 257 | } |
| 258 | |
| 259 | /* Release ioremapped memory */ |
| 260 | static void cx18_iounmap(struct cx18 *cx) |
| 261 | { |
| 262 | if (cx == NULL) |
| 263 | return; |
| 264 | |
| 265 | /* Release io memory */ |
| 266 | if (cx->enc_mem != NULL) { |
| 267 | CX18_DEBUG_INFO("releasing enc_mem\n"); |
| 268 | iounmap(cx->enc_mem); |
| 269 | cx->enc_mem = NULL; |
| 270 | } |
| 271 | } |
| 272 | |
Andy Walls | 25a42e4 | 2009-07-05 17:09:28 -0300 | [diff] [blame] | 273 | static void cx18_eeprom_dump(struct cx18 *cx, unsigned char *eedata, int len) |
| 274 | { |
| 275 | int i; |
| 276 | |
| 277 | CX18_INFO("eeprom dump:\n"); |
| 278 | for (i = 0; i < len; i++) { |
| 279 | if (0 == (i % 16)) |
| 280 | CX18_INFO("eeprom %02x:", i); |
| 281 | printk(KERN_CONT " %02x", eedata[i]); |
| 282 | if (15 == (i % 16)) |
| 283 | printk(KERN_CONT "\n"); |
| 284 | } |
| 285 | } |
| 286 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 287 | /* Hauppauge card? get values from tveeprom */ |
| 288 | void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv) |
| 289 | { |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 290 | struct i2c_client c; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 291 | u8 eedata[256]; |
| 292 | |
Andy Walls | 6246d4e | 2009-02-21 22:27:37 -0300 | [diff] [blame] | 293 | memset(&c, 0, sizeof(c)); |
Andy Walls | 098003d | 2009-02-28 13:19:45 -0300 | [diff] [blame] | 294 | strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name)); |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 295 | c.adapter = &cx->i2c_adap[0]; |
| 296 | c.addr = 0xA0 >> 1; |
| 297 | |
Andy Walls | 25a42e4 | 2009-07-05 17:09:28 -0300 | [diff] [blame] | 298 | memset(tv, 0, sizeof(*tv)); |
| 299 | if (tveeprom_read(&c, eedata, sizeof(eedata))) |
| 300 | return; |
| 301 | |
| 302 | switch (cx->card->type) { |
| 303 | case CX18_CARD_HVR_1600_ESMT: |
| 304 | case CX18_CARD_HVR_1600_SAMSUNG: |
| 305 | tveeprom_hauppauge_analog(&c, tv, eedata); |
| 306 | break; |
| 307 | case CX18_CARD_YUAN_MPC718: |
| 308 | tv->model = 0x718; |
| 309 | cx18_eeprom_dump(cx, eedata, sizeof(eedata)); |
| 310 | CX18_INFO("eeprom PCI ID: %02x%02x:%02x%02x\n", |
| 311 | eedata[2], eedata[1], eedata[4], eedata[3]); |
| 312 | break; |
| 313 | default: |
| 314 | tv->model = 0xffffffff; |
| 315 | cx18_eeprom_dump(cx, eedata, sizeof(eedata)); |
| 316 | break; |
| 317 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static void cx18_process_eeprom(struct cx18 *cx) |
| 321 | { |
| 322 | struct tveeprom tv; |
| 323 | |
| 324 | cx18_read_eeprom(cx, &tv); |
| 325 | |
| 326 | /* Many thanks to Steven Toth from Hauppauge for providing the |
| 327 | model numbers */ |
Hans Verkuil | 1d08160 | 2008-05-12 14:45:19 -0300 | [diff] [blame] | 328 | /* Note: the Samsung memory models cannot be reliably determined |
| 329 | from the model number. Use the cardtype module option if you |
| 330 | have one of these preproduction models. */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 331 | switch (tv.model) { |
Hans Verkuil | 1d08160 | 2008-05-12 14:45:19 -0300 | [diff] [blame] | 332 | case 74000 ... 74999: |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 333 | cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); |
| 334 | break; |
Andy Walls | 25a42e4 | 2009-07-05 17:09:28 -0300 | [diff] [blame] | 335 | case 0x718: |
| 336 | return; |
| 337 | case 0xffffffff: |
| 338 | CX18_INFO("Unknown EEPROM encoding\n"); |
| 339 | return; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 340 | case 0: |
| 341 | CX18_ERR("Invalid EEPROM\n"); |
| 342 | return; |
| 343 | default: |
| 344 | CX18_ERR("Unknown model %d, defaulting to HVR-1600\n", tv.model); |
| 345 | cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); |
| 346 | break; |
| 347 | } |
| 348 | |
| 349 | cx->v4l2_cap = cx->card->v4l2_capabilities; |
| 350 | cx->card_name = cx->card->name; |
| 351 | cx->card_i2c = cx->card->i2c; |
| 352 | |
| 353 | CX18_INFO("Autodetected %s\n", cx->card_name); |
| 354 | |
| 355 | if (tv.tuner_type == TUNER_ABSENT) |
Andy Walls | 4442ee8 | 2009-05-09 00:34:31 -0300 | [diff] [blame] | 356 | CX18_ERR("tveeprom cannot autodetect tuner!\n"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 357 | |
| 358 | if (cx->options.tuner == -1) |
| 359 | cx->options.tuner = tv.tuner_type; |
| 360 | if (cx->options.radio == -1) |
| 361 | cx->options.radio = (tv.has_radio != 0); |
| 362 | |
| 363 | if (cx->std != 0) |
| 364 | /* user specified tuner standard */ |
| 365 | return; |
| 366 | |
| 367 | /* autodetect tuner standard */ |
| 368 | if (tv.tuner_formats & V4L2_STD_PAL) { |
| 369 | CX18_DEBUG_INFO("PAL tuner detected\n"); |
| 370 | cx->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H; |
| 371 | } else if (tv.tuner_formats & V4L2_STD_NTSC) { |
| 372 | CX18_DEBUG_INFO("NTSC tuner detected\n"); |
| 373 | cx->std |= V4L2_STD_NTSC_M; |
| 374 | } else if (tv.tuner_formats & V4L2_STD_SECAM) { |
| 375 | CX18_DEBUG_INFO("SECAM tuner detected\n"); |
| 376 | cx->std |= V4L2_STD_SECAM_L; |
| 377 | } else { |
| 378 | CX18_INFO("No tuner detected, default to NTSC-M\n"); |
| 379 | cx->std |= V4L2_STD_NTSC_M; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static v4l2_std_id cx18_parse_std(struct cx18 *cx) |
| 384 | { |
| 385 | switch (pal[0]) { |
| 386 | case '6': |
| 387 | return V4L2_STD_PAL_60; |
| 388 | case 'b': |
| 389 | case 'B': |
| 390 | case 'g': |
| 391 | case 'G': |
| 392 | return V4L2_STD_PAL_BG; |
| 393 | case 'h': |
| 394 | case 'H': |
| 395 | return V4L2_STD_PAL_H; |
| 396 | case 'n': |
| 397 | case 'N': |
| 398 | if (pal[1] == 'c' || pal[1] == 'C') |
| 399 | return V4L2_STD_PAL_Nc; |
| 400 | return V4L2_STD_PAL_N; |
| 401 | case 'i': |
| 402 | case 'I': |
| 403 | return V4L2_STD_PAL_I; |
| 404 | case 'd': |
| 405 | case 'D': |
| 406 | case 'k': |
| 407 | case 'K': |
| 408 | return V4L2_STD_PAL_DK; |
| 409 | case 'M': |
| 410 | case 'm': |
| 411 | return V4L2_STD_PAL_M; |
| 412 | case '-': |
| 413 | break; |
| 414 | default: |
| 415 | CX18_WARN("pal= argument not recognised\n"); |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | switch (secam[0]) { |
| 420 | case 'b': |
| 421 | case 'B': |
| 422 | case 'g': |
| 423 | case 'G': |
| 424 | case 'h': |
| 425 | case 'H': |
| 426 | return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H; |
| 427 | case 'd': |
| 428 | case 'D': |
| 429 | case 'k': |
| 430 | case 'K': |
| 431 | return V4L2_STD_SECAM_DK; |
| 432 | case 'l': |
| 433 | case 'L': |
| 434 | if (secam[1] == 'C' || secam[1] == 'c') |
| 435 | return V4L2_STD_SECAM_LC; |
| 436 | return V4L2_STD_SECAM_L; |
| 437 | case '-': |
| 438 | break; |
| 439 | default: |
| 440 | CX18_WARN("secam= argument not recognised\n"); |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | switch (ntsc[0]) { |
| 445 | case 'm': |
| 446 | case 'M': |
| 447 | return V4L2_STD_NTSC_M; |
| 448 | case 'j': |
| 449 | case 'J': |
| 450 | return V4L2_STD_NTSC_M_JP; |
| 451 | case 'k': |
| 452 | case 'K': |
| 453 | return V4L2_STD_NTSC_M_KR; |
| 454 | case '-': |
| 455 | break; |
| 456 | default: |
| 457 | CX18_WARN("ntsc= argument not recognised\n"); |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | /* no match found */ |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static void cx18_process_options(struct cx18 *cx) |
| 466 | { |
| 467 | int i, j; |
| 468 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 469 | cx->options.megabytes[CX18_ENC_STREAM_TYPE_TS] = enc_ts_buffers; |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 470 | cx->options.megabytes[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers; |
| 471 | cx->options.megabytes[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_buffers; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 472 | cx->options.megabytes[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers; |
| 473 | cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers; |
| 474 | cx->options.megabytes[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers; |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 475 | cx->options.megabytes[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control only */ |
| 476 | |
| 477 | cx->stream_buffers[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufs; |
| 478 | cx->stream_buffers[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufs; |
| 479 | cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufs; |
| 480 | cx->stream_buffers[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufs; |
| 481 | cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_bufs; |
| 482 | cx->stream_buffers[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufs; |
| 483 | cx->stream_buffers[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control, no data */ |
| 484 | |
| 485 | cx->stream_buf_size[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufsize; |
| 486 | cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufsize; |
| 487 | cx->stream_buf_size[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufsize; |
| 488 | cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufsize; |
Andy Walls | 466df46 | 2009-02-07 15:47:28 -0300 | [diff] [blame] | 489 | cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = vbi_active_samples * 36; |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 490 | cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufsize; |
| 491 | cx->stream_buf_size[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control no data */ |
| 492 | |
Andy Walls | 466df46 | 2009-02-07 15:47:28 -0300 | [diff] [blame] | 493 | /* Ensure stream_buffers & stream_buf_size are valid */ |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 494 | for (i = 0; i < CX18_MAX_STREAMS; i++) { |
Andy Walls | 466df46 | 2009-02-07 15:47:28 -0300 | [diff] [blame] | 495 | if (cx->stream_buffers[i] == 0 || /* User said 0 buffers */ |
| 496 | cx->options.megabytes[i] <= 0 || /* User said 0 MB total */ |
| 497 | cx->stream_buf_size[i] <= 0) { /* User said buf size 0 */ |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 498 | cx->options.megabytes[i] = 0; |
| 499 | cx->stream_buffers[i] = 0; |
| 500 | cx->stream_buf_size[i] = 0; |
| 501 | continue; |
| 502 | } |
Andy Walls | 466df46 | 2009-02-07 15:47:28 -0300 | [diff] [blame] | 503 | /* |
Andy Walls | 22dce18 | 2009-11-09 23:55:30 -0300 | [diff] [blame^] | 504 | * YUV is a special case where the stream_buf_size needs to be |
| 505 | * an integral multiple of 33.75 kB (storage for 32 screens |
| 506 | * lines to maintain alignment in case of lost buffers |
| 507 | */ |
| 508 | if (i == CX18_ENC_STREAM_TYPE_YUV) { |
| 509 | cx->stream_buf_size[i] *= 1024; |
| 510 | cx->stream_buf_size[i] -= |
| 511 | (cx->stream_buf_size[i] % CX18_UNIT_ENC_YUV_BUFSIZE); |
| 512 | |
| 513 | if (cx->stream_buf_size[i] < CX18_UNIT_ENC_YUV_BUFSIZE) |
| 514 | cx->stream_buf_size[i] = |
| 515 | CX18_UNIT_ENC_YUV_BUFSIZE; |
| 516 | } |
| 517 | /* |
| 518 | * YUV is a special case where the stream_buf_size is |
| 519 | * now in bytes. |
Andy Walls | 466df46 | 2009-02-07 15:47:28 -0300 | [diff] [blame] | 520 | * VBI is a special case where the stream_buf_size is fixed |
| 521 | * and already in bytes |
| 522 | */ |
Andy Walls | 22dce18 | 2009-11-09 23:55:30 -0300 | [diff] [blame^] | 523 | if (i == CX18_ENC_STREAM_TYPE_VBI || |
| 524 | i == CX18_ENC_STREAM_TYPE_YUV) { |
Andy Walls | 466df46 | 2009-02-07 15:47:28 -0300 | [diff] [blame] | 525 | if (cx->stream_buffers[i] < 0) { |
| 526 | cx->stream_buffers[i] = |
| 527 | cx->options.megabytes[i] * 1024 * 1024 |
| 528 | / cx->stream_buf_size[i]; |
| 529 | } else { |
| 530 | /* N.B. This might round down to 0 */ |
| 531 | cx->options.megabytes[i] = |
| 532 | cx->stream_buffers[i] |
| 533 | * cx->stream_buf_size[i]/(1024 * 1024); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 534 | } |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 535 | } else { |
Andy Walls | 22dce18 | 2009-11-09 23:55:30 -0300 | [diff] [blame^] | 536 | /* All other streams have stream_buf_size in kB here */ |
| 537 | if (cx->stream_buffers[i] < 0) { |
| 538 | cx->stream_buffers[i] = |
| 539 | cx->options.megabytes[i] * 1024 |
| 540 | / cx->stream_buf_size[i]; |
| 541 | } else { |
| 542 | /* N.B. This might round down to 0 */ |
| 543 | cx->options.megabytes[i] = |
| 544 | cx->stream_buffers[i] |
| 545 | * cx->stream_buf_size[i] / 1024; |
| 546 | } |
| 547 | /* convert from kB to bytes */ |
| 548 | cx->stream_buf_size[i] *= 1024; |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 549 | } |
Andy Walls | 22dce18 | 2009-11-09 23:55:30 -0300 | [diff] [blame^] | 550 | CX18_DEBUG_INFO("Stream type %d options: %d MB, %d buffers, " |
| 551 | "%d bytes\n", i, cx->options.megabytes[i], |
| 552 | cx->stream_buffers[i], cx->stream_buf_size[i]); |
Andy Walls | 6ecd86d | 2008-12-07 23:30:17 -0300 | [diff] [blame] | 553 | } |
| 554 | |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 555 | cx->options.cardtype = cardtype[cx->instance]; |
| 556 | cx->options.tuner = tuner[cx->instance]; |
| 557 | cx->options.radio = radio[cx->instance]; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 558 | |
| 559 | cx->std = cx18_parse_std(cx); |
| 560 | if (cx->options.cardtype == -1) { |
| 561 | CX18_INFO("Ignore card\n"); |
| 562 | return; |
| 563 | } |
| 564 | cx->card = cx18_get_card(cx->options.cardtype - 1); |
| 565 | if (cx->card) |
| 566 | CX18_INFO("User specified %s card\n", cx->card->name); |
| 567 | else if (cx->options.cardtype != 0) |
| 568 | CX18_ERR("Unknown user specified type, trying to autodetect card\n"); |
| 569 | if (cx->card == NULL) { |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 570 | if (cx->pci_dev->subsystem_vendor == CX18_PCI_ID_HAUPPAUGE) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 571 | cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); |
| 572 | CX18_INFO("Autodetected Hauppauge card\n"); |
| 573 | } |
| 574 | } |
| 575 | if (cx->card == NULL) { |
| 576 | for (i = 0; (cx->card = cx18_get_card(i)); i++) { |
| 577 | if (cx->card->pci_list == NULL) |
| 578 | continue; |
| 579 | for (j = 0; cx->card->pci_list[j].device; j++) { |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 580 | if (cx->pci_dev->device != |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 581 | cx->card->pci_list[j].device) |
| 582 | continue; |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 583 | if (cx->pci_dev->subsystem_vendor != |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 584 | cx->card->pci_list[j].subsystem_vendor) |
| 585 | continue; |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 586 | if (cx->pci_dev->subsystem_device != |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 587 | cx->card->pci_list[j].subsystem_device) |
| 588 | continue; |
| 589 | CX18_INFO("Autodetected %s card\n", cx->card->name); |
| 590 | goto done; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | done: |
| 595 | |
| 596 | if (cx->card == NULL) { |
| 597 | cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); |
Bjorn Helgaas | 29e66a6 | 2008-09-04 17:24:51 -0300 | [diff] [blame] | 598 | CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n", |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 599 | cx->pci_dev->vendor, cx->pci_dev->device); |
Bjorn Helgaas | 29e66a6 | 2008-09-04 17:24:51 -0300 | [diff] [blame] | 600 | CX18_ERR(" subsystem vendor/device: [%04x:%04x]\n", |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 601 | cx->pci_dev->subsystem_vendor, |
| 602 | cx->pci_dev->subsystem_device); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 603 | CX18_ERR("Defaulting to %s card\n", cx->card->name); |
| 604 | CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n"); |
| 605 | CX18_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n"); |
| 606 | CX18_ERR("Prefix your subject line with [UNKNOWN CX18 CARD].\n"); |
| 607 | } |
| 608 | cx->v4l2_cap = cx->card->v4l2_capabilities; |
| 609 | cx->card_name = cx->card->name; |
| 610 | cx->card_i2c = cx->card->i2c; |
| 611 | } |
| 612 | |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 613 | static int __devinit cx18_create_in_workq(struct cx18 *cx) |
| 614 | { |
| 615 | snprintf(cx->in_workq_name, sizeof(cx->in_workq_name), "%s-in", |
| 616 | cx->v4l2_dev.name); |
| 617 | cx->in_work_queue = create_singlethread_workqueue(cx->in_workq_name); |
| 618 | if (cx->in_work_queue == NULL) { |
| 619 | CX18_ERR("Unable to create incoming mailbox handler thread\n"); |
| 620 | return -ENOMEM; |
| 621 | } |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | static int __devinit cx18_create_out_workq(struct cx18 *cx) |
| 626 | { |
| 627 | snprintf(cx->out_workq_name, sizeof(cx->out_workq_name), "%s-out", |
| 628 | cx->v4l2_dev.name); |
| 629 | cx->out_work_queue = create_workqueue(cx->out_workq_name); |
| 630 | if (cx->out_work_queue == NULL) { |
| 631 | CX18_ERR("Unable to create outgoing mailbox handler threads\n"); |
| 632 | return -ENOMEM; |
| 633 | } |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | static void __devinit cx18_init_in_work_orders(struct cx18 *cx) |
| 638 | { |
| 639 | int i; |
| 640 | for (i = 0; i < CX18_MAX_IN_WORK_ORDERS; i++) { |
| 641 | cx->in_work_order[i].cx = cx; |
| 642 | cx->in_work_order[i].str = cx->epu_debug_str; |
| 643 | INIT_WORK(&cx->in_work_order[i].work, cx18_in_work_handler); |
| 644 | } |
| 645 | } |
| 646 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 647 | /* Precondition: the cx18 structure has been memset to 0. Only |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 648 | the dev and instance fields have been filled in. |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 649 | No assumptions on the card type may be made here (see cx18_init_struct2 |
| 650 | for that). |
| 651 | */ |
| 652 | static int __devinit cx18_init_struct1(struct cx18 *cx) |
| 653 | { |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 654 | int ret; |
Andy Walls | ee2d64f | 2008-11-16 01:38:19 -0300 | [diff] [blame] | 655 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 656 | cx->base_addr = pci_resource_start(cx->pci_dev, 0); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 657 | |
| 658 | mutex_init(&cx->serialize_lock); |
Andy Walls | 8abdd00 | 2008-07-13 19:05:25 -0300 | [diff] [blame] | 659 | mutex_init(&cx->gpio_lock); |
Andy Walls | 72c2d6d | 2008-11-06 01:15:41 -0300 | [diff] [blame] | 660 | mutex_init(&cx->epu2apu_mb_lock); |
| 661 | mutex_init(&cx->epu2cpu_mb_lock); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 662 | |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 663 | ret = cx18_create_out_workq(cx); |
| 664 | if (ret) |
| 665 | return ret; |
| 666 | |
| 667 | ret = cx18_create_in_workq(cx); |
| 668 | if (ret) { |
| 669 | destroy_workqueue(cx->out_work_queue); |
| 670 | return ret; |
Andy Walls | 572bfea | 2008-11-25 21:43:05 -0300 | [diff] [blame] | 671 | } |
| 672 | |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 673 | cx18_init_in_work_orders(cx); |
Andy Walls | 1d6782b | 2008-11-05 00:49:14 -0300 | [diff] [blame] | 674 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 675 | /* start counting open_id at 1 */ |
| 676 | cx->open_id = 1; |
| 677 | |
| 678 | /* Initial settings */ |
| 679 | cx2341x_fill_defaults(&cx->params); |
| 680 | cx->temporal_strength = cx->params.video_temporal_filter; |
| 681 | cx->spatial_strength = cx->params.video_spatial_filter; |
| 682 | cx->filter_mode = cx->params.video_spatial_filter_mode | |
| 683 | (cx->params.video_temporal_filter_mode << 1) | |
| 684 | (cx->params.video_median_filter_type << 2); |
| 685 | cx->params.port = CX2341X_PORT_MEMORY; |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 686 | cx->params.capabilities = |
Andy Walls | 006e717 | 2009-02-21 22:44:50 -0300 | [diff] [blame] | 687 | CX2341X_CAP_HAS_TS | CX2341X_CAP_HAS_SLICED_VBI; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 688 | init_waitqueue_head(&cx->cap_w); |
| 689 | init_waitqueue_head(&cx->mb_apu_waitq); |
| 690 | init_waitqueue_head(&cx->mb_cpu_waitq); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 691 | init_waitqueue_head(&cx->dma_waitq); |
| 692 | |
| 693 | /* VBI */ |
Andy Walls | dd07343 | 2008-12-12 16:24:04 -0300 | [diff] [blame] | 694 | cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 695 | cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced; |
Andy Walls | af009cf | 2008-12-12 20:00:29 -0300 | [diff] [blame] | 696 | |
Andy Walls | 52fcb3e | 2009-11-08 23:45:24 -0300 | [diff] [blame] | 697 | /* IVTV style VBI insertion into MPEG streams */ |
| 698 | INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_buf.list); |
| 699 | INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.list); |
| 700 | INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.buf_list); |
| 701 | list_add(&cx->vbi.sliced_mpeg_buf.list, |
| 702 | &cx->vbi.sliced_mpeg_mdl.buf_list); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | /* Second initialization part. Here the card type has been |
| 707 | autodetected. */ |
| 708 | static void __devinit cx18_init_struct2(struct cx18 *cx) |
| 709 | { |
| 710 | int i; |
| 711 | |
| 712 | for (i = 0; i < CX18_CARD_MAX_VIDEO_INPUTS; i++) |
| 713 | if (cx->card->video_inputs[i].video_type == 0) |
| 714 | break; |
| 715 | cx->nof_inputs = i; |
| 716 | for (i = 0; i < CX18_CARD_MAX_AUDIO_INPUTS; i++) |
| 717 | if (cx->card->audio_inputs[i].audio_type == 0) |
| 718 | break; |
| 719 | cx->nof_audio_inputs = i; |
| 720 | |
| 721 | /* Find tuner input */ |
| 722 | for (i = 0; i < cx->nof_inputs; i++) { |
| 723 | if (cx->card->video_inputs[i].video_type == |
| 724 | CX18_CARD_INPUT_VID_TUNER) |
| 725 | break; |
| 726 | } |
| 727 | if (i == cx->nof_inputs) |
| 728 | i = 0; |
| 729 | cx->active_input = i; |
| 730 | cx->audio_input = cx->card->video_inputs[i].audio_index; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 731 | } |
| 732 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 733 | static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *pci_dev, |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 734 | const struct pci_device_id *pci_id) |
| 735 | { |
| 736 | u16 cmd; |
| 737 | unsigned char pci_latency; |
| 738 | |
| 739 | CX18_DEBUG_INFO("Enabling pci device\n"); |
| 740 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 741 | if (pci_enable_device(pci_dev)) { |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 742 | CX18_ERR("Can't enable device %d!\n", cx->instance); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 743 | return -EIO; |
| 744 | } |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 745 | if (pci_set_dma_mask(pci_dev, 0xffffffff)) { |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 746 | CX18_ERR("No suitable DMA available, card %d\n", cx->instance); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 747 | return -EIO; |
| 748 | } |
| 749 | if (!request_mem_region(cx->base_addr, CX18_MEM_SIZE, "cx18 encoder")) { |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 750 | CX18_ERR("Cannot request encoder memory region, card %d\n", |
| 751 | cx->instance); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 752 | return -EIO; |
| 753 | } |
| 754 | |
Andy Walls | 4519064 | 2008-08-29 16:10:21 -0300 | [diff] [blame] | 755 | /* Enable bus mastering and memory mapped IO for the CX23418 */ |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 756 | pci_read_config_word(pci_dev, PCI_COMMAND, &cmd); |
Andy Walls | 4519064 | 2008-08-29 16:10:21 -0300 | [diff] [blame] | 757 | cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 758 | pci_write_config_word(pci_dev, PCI_COMMAND, cmd); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 759 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 760 | pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &cx->card_rev); |
| 761 | pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &pci_latency); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 762 | |
| 763 | if (pci_latency < 64 && cx18_pci_latency) { |
| 764 | CX18_INFO("Unreasonably low latency timer, " |
| 765 | "setting to 64 (was %d)\n", pci_latency); |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 766 | pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, 64); |
| 767 | pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &pci_latency); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 768 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 769 | |
| 770 | CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, " |
| 771 | "irq: %d, latency: %d, memory: 0x%lx\n", |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 772 | cx->pci_dev->device, cx->card_rev, pci_dev->bus->number, |
| 773 | PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn), |
| 774 | cx->pci_dev->irq, pci_latency, (unsigned long)cx->base_addr); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 779 | static void cx18_init_subdevs(struct cx18 *cx) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 780 | { |
| 781 | u32 hw = cx->card->hw_all; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 782 | u32 device; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 783 | int i; |
| 784 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 785 | for (i = 0, device = 1; i < 32; i++, device <<= 1) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 786 | |
| 787 | if (!(device & hw)) |
| 788 | continue; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 789 | |
| 790 | switch (device) { |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 791 | case CX18_HW_DVB: |
| 792 | case CX18_HW_TVEEPROM: |
| 793 | /* These subordinate devices do not use probing */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 794 | cx->hw_flags |= device; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 795 | break; |
| 796 | case CX18_HW_418_AV: |
| 797 | /* The A/V decoder gets probed earlier to set PLLs */ |
| 798 | /* Just note that the card uses it (i.e. has analog) */ |
| 799 | cx->hw_flags |= device; |
| 800 | break; |
Andy Walls | eefe101 | 2009-02-21 18:42:49 -0300 | [diff] [blame] | 801 | case CX18_HW_GPIO_RESET_CTRL: |
| 802 | /* |
| 803 | * The Reset Controller gets probed and added to |
| 804 | * hw_flags earlier for i2c adapter/bus initialization |
| 805 | */ |
| 806 | break; |
| 807 | case CX18_HW_GPIO_MUX: |
| 808 | if (cx18_gpio_register(cx, device) == 0) |
| 809 | cx->hw_flags |= device; |
| 810 | break; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 811 | default: |
| 812 | if (cx18_i2c_register(cx, i) == 0) |
| 813 | cx->hw_flags |= device; |
| 814 | break; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 815 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 816 | } |
| 817 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 818 | if (cx->hw_flags & CX18_HW_418_AV) |
| 819 | cx->sd_av = cx18_find_hw(cx, CX18_HW_418_AV); |
| 820 | |
| 821 | if (cx->card->hw_muxer != 0) |
| 822 | cx->sd_extmux = cx18_find_hw(cx, cx->card->hw_muxer); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 823 | } |
| 824 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 825 | static int __devinit cx18_probe(struct pci_dev *pci_dev, |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 826 | const struct pci_device_id *pci_id) |
| 827 | { |
| 828 | int retval = 0; |
Andy Walls | ff08657 | 2008-10-18 08:51:28 -0300 | [diff] [blame] | 829 | int i; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 830 | u32 devtype; |
| 831 | struct cx18 *cx; |
| 832 | |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 833 | /* FIXME - module parameter arrays constrain max instances */ |
| 834 | i = atomic_inc_return(&cx18_instance) - 1; |
| 835 | if (i >= CX18_MAX_CARDS) { |
| 836 | printk(KERN_ERR "cx18: cannot manage card %d, driver has a " |
| 837 | "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 838 | return -ENOMEM; |
| 839 | } |
| 840 | |
| 841 | cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC); |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 842 | if (cx == NULL) { |
| 843 | printk(KERN_ERR "cx18: cannot manage card %d, out of memory\n", |
| 844 | i); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 845 | return -ENOMEM; |
| 846 | } |
Andy Walls | 888cdb0 | 2009-01-11 15:08:53 -0300 | [diff] [blame] | 847 | cx->pci_dev = pci_dev; |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 848 | cx->instance = i; |
| 849 | |
Andy Walls | 888cdb0 | 2009-01-11 15:08:53 -0300 | [diff] [blame] | 850 | retval = v4l2_device_register(&pci_dev->dev, &cx->v4l2_dev); |
| 851 | if (retval) { |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 852 | printk(KERN_ERR "cx18: v4l2_device_register of card %d failed" |
| 853 | "\n", cx->instance); |
| 854 | kfree(cx); |
| 855 | return retval; |
Andy Walls | 888cdb0 | 2009-01-11 15:08:53 -0300 | [diff] [blame] | 856 | } |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 857 | snprintf(cx->v4l2_dev.name, sizeof(cx->v4l2_dev.name), "cx18-%d", |
| 858 | cx->instance); |
| 859 | CX18_INFO("Initializing card %d\n", cx->instance); |
Andy Walls | 888cdb0 | 2009-01-11 15:08:53 -0300 | [diff] [blame] | 860 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 861 | cx18_process_options(cx); |
| 862 | if (cx->options.cardtype == -1) { |
| 863 | retval = -ENODEV; |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 864 | goto err; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 865 | } |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 866 | |
| 867 | retval = cx18_init_struct1(cx); |
| 868 | if (retval) |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 869 | goto err; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 870 | |
| 871 | CX18_DEBUG_INFO("base addr: 0x%08x\n", cx->base_addr); |
| 872 | |
| 873 | /* PCI Device Setup */ |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 874 | retval = cx18_setup_pci(cx, pci_dev, pci_id); |
Andy Walls | 572bfea | 2008-11-25 21:43:05 -0300 | [diff] [blame] | 875 | if (retval != 0) |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 876 | goto free_workqueues; |
Andy Walls | 572bfea | 2008-11-25 21:43:05 -0300 | [diff] [blame] | 877 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 878 | /* map io memory */ |
| 879 | CX18_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n", |
| 880 | cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); |
| 881 | cx->enc_mem = ioremap_nocache(cx->base_addr + CX18_MEM_OFFSET, |
| 882 | CX18_MEM_SIZE); |
| 883 | if (!cx->enc_mem) { |
| 884 | CX18_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); |
| 885 | CX18_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n"); |
| 886 | retval = -ENOMEM; |
| 887 | goto free_mem; |
| 888 | } |
| 889 | cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET; |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 890 | devtype = cx18_read_reg(cx, 0xC72028); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 891 | switch (devtype & 0xff000000) { |
| 892 | case 0xff000000: |
| 893 | CX18_INFO("cx23418 revision %08x (A)\n", devtype); |
| 894 | break; |
| 895 | case 0x01000000: |
| 896 | CX18_INFO("cx23418 revision %08x (B)\n", devtype); |
| 897 | break; |
| 898 | default: |
| 899 | CX18_INFO("cx23418 revision %08x (Unknown)\n", devtype); |
| 900 | break; |
| 901 | } |
| 902 | |
| 903 | cx18_init_power(cx, 1); |
| 904 | cx18_init_memory(cx); |
| 905 | |
Al Viro | 990c81c | 2008-05-21 00:32:01 -0300 | [diff] [blame] | 906 | cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 907 | cx18_init_scb(cx); |
| 908 | |
| 909 | cx18_gpio_init(cx); |
| 910 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 911 | /* Initialize integrated A/V decoder early to set PLLs, just in case */ |
| 912 | retval = cx18_av_probe(cx); |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 913 | if (retval) { |
| 914 | CX18_ERR("Could not register A/V decoder subdevice\n"); |
| 915 | goto free_map; |
| 916 | } |
Hans Verkuil | cc26b07 | 2009-03-29 19:20:26 -0300 | [diff] [blame] | 917 | cx18_call_hw(cx, CX18_HW_418_AV, core, init, 0); |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 918 | |
Andy Walls | eefe101 | 2009-02-21 18:42:49 -0300 | [diff] [blame] | 919 | /* Initialize GPIO Reset Controller to do chip resets during i2c init */ |
| 920 | if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) { |
| 921 | if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0) |
| 922 | CX18_WARN("Could not register GPIO reset controller" |
| 923 | "subdevice; proceeding anyway.\n"); |
| 924 | else |
| 925 | cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL; |
| 926 | } |
| 927 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 928 | /* active i2c */ |
| 929 | CX18_DEBUG_INFO("activating i2c...\n"); |
Andy Walls | 9b4a7c8 | 2008-10-18 10:20:25 -0300 | [diff] [blame] | 930 | retval = init_cx18_i2c(cx); |
| 931 | if (retval) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 932 | CX18_ERR("Could not initialize i2c\n"); |
| 933 | goto free_map; |
| 934 | } |
| 935 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 936 | if (cx->card->hw_all & CX18_HW_TVEEPROM) { |
| 937 | /* Based on the model number the cardtype may be changed. |
| 938 | The PCI IDs are not always reliable. */ |
| 939 | cx18_process_eeprom(cx); |
| 940 | } |
| 941 | if (cx->card->comment) |
| 942 | CX18_INFO("%s", cx->card->comment); |
| 943 | if (cx->card->v4l2_capabilities == 0) { |
| 944 | retval = -ENODEV; |
| 945 | goto free_i2c; |
| 946 | } |
| 947 | cx18_init_memory(cx); |
Andy Walls | fd6b9c9 | 2008-12-14 21:26:25 -0300 | [diff] [blame] | 948 | cx18_init_scb(cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 949 | |
| 950 | /* Register IRQ */ |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 951 | retval = request_irq(cx->pci_dev->irq, cx18_irq_handler, |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 952 | IRQF_SHARED | IRQF_DISABLED, |
| 953 | cx->v4l2_dev.name, (void *)cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 954 | if (retval) { |
| 955 | CX18_ERR("Failed to register irq %d\n", retval); |
| 956 | goto free_i2c; |
| 957 | } |
| 958 | |
| 959 | if (cx->std == 0) |
| 960 | cx->std = V4L2_STD_NTSC_M; |
| 961 | |
| 962 | if (cx->options.tuner == -1) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 963 | for (i = 0; i < CX18_CARD_MAX_TUNERS; i++) { |
| 964 | if ((cx->std & cx->card->tuners[i].std) == 0) |
| 965 | continue; |
| 966 | cx->options.tuner = cx->card->tuners[i].tuner; |
| 967 | break; |
| 968 | } |
| 969 | } |
| 970 | /* if no tuner was found, then pick the first tuner in the card list */ |
| 971 | if (cx->options.tuner == -1 && cx->card->tuners[0].std) { |
| 972 | cx->std = cx->card->tuners[0].std; |
Hans Verkuil | c3cb4d9 | 2008-06-27 23:27:25 -0300 | [diff] [blame] | 973 | if (cx->std & V4L2_STD_PAL) |
| 974 | cx->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H; |
| 975 | else if (cx->std & V4L2_STD_NTSC) |
| 976 | cx->std = V4L2_STD_NTSC_M; |
| 977 | else if (cx->std & V4L2_STD_SECAM) |
| 978 | cx->std = V4L2_STD_SECAM_L; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 979 | cx->options.tuner = cx->card->tuners[0].tuner; |
| 980 | } |
| 981 | if (cx->options.radio == -1) |
| 982 | cx->options.radio = (cx->card->radio_input.audio_type != 0); |
| 983 | |
| 984 | /* The card is now fully identified, continue with card-specific |
| 985 | initialization. */ |
| 986 | cx18_init_struct2(cx); |
| 987 | |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 988 | cx18_init_subdevs(cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 989 | |
Andy Walls | 8d037ed | 2009-02-21 22:35:11 -0300 | [diff] [blame] | 990 | if (cx->std & V4L2_STD_525_60) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 991 | cx->is_60hz = 1; |
Andy Walls | 8d037ed | 2009-02-21 22:35:11 -0300 | [diff] [blame] | 992 | else |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 993 | cx->is_50hz = 1; |
Andy Walls | 8d037ed | 2009-02-21 22:35:11 -0300 | [diff] [blame] | 994 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 995 | cx->params.video_gop_size = cx->is_60hz ? 15 : 12; |
| 996 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 997 | if (cx->options.radio > 0) |
| 998 | cx->v4l2_cap |= V4L2_CAP_RADIO; |
| 999 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1000 | if (cx->options.tuner > -1) { |
| 1001 | struct tuner_setup setup; |
| 1002 | |
| 1003 | setup.addr = ADDR_UNSET; |
| 1004 | setup.type = cx->options.tuner; |
| 1005 | setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ |
| 1006 | setup.tuner_callback = (setup.type == TUNER_XC2028) ? |
| 1007 | cx18_reset_tuner_gpio : NULL; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 1008 | cx18_call_all(cx, tuner, s_type_addr, &setup); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1009 | if (setup.type == TUNER_XC2028) { |
| 1010 | static struct xc2028_ctrl ctrl = { |
| 1011 | .fname = XC2028_DEFAULT_FIRMWARE, |
| 1012 | .max_len = 64, |
| 1013 | }; |
| 1014 | struct v4l2_priv_tun_config cfg = { |
| 1015 | .tuner = cx->options.tuner, |
| 1016 | .priv = &ctrl, |
| 1017 | }; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 1018 | cx18_call_all(cx, tuner, s_config, &cfg); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | /* The tuner is fixed to the standard. The other inputs (e.g. S-Video) |
| 1023 | are not. */ |
| 1024 | cx->tuner_std = cx->std; |
| 1025 | |
Hans Verkuil | 5e7fdc5 | 2008-05-30 10:51:53 -0300 | [diff] [blame] | 1026 | retval = cx18_streams_setup(cx); |
| 1027 | if (retval) { |
| 1028 | CX18_ERR("Error %d setting up streams\n", retval); |
| 1029 | goto free_irq; |
| 1030 | } |
| 1031 | retval = cx18_streams_register(cx); |
| 1032 | if (retval) { |
| 1033 | CX18_ERR("Error %d registering devices\n", retval); |
| 1034 | goto free_streams; |
| 1035 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1036 | |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1037 | CX18_INFO("Initialized card: %s\n", cx->card_name); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1038 | return 0; |
| 1039 | |
| 1040 | free_streams: |
Hans Verkuil | 3f98387 | 2008-05-01 10:31:12 -0300 | [diff] [blame] | 1041 | cx18_streams_cleanup(cx, 1); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1042 | free_irq: |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 1043 | free_irq(cx->pci_dev->irq, (void *)cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1044 | free_i2c: |
| 1045 | exit_cx18_i2c(cx); |
| 1046 | free_map: |
| 1047 | cx18_iounmap(cx); |
| 1048 | free_mem: |
| 1049 | release_mem_region(cx->base_addr, CX18_MEM_SIZE); |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 1050 | free_workqueues: |
Andy Walls | deed75e | 2009-04-13 22:22:40 -0300 | [diff] [blame] | 1051 | destroy_workqueue(cx->in_work_queue); |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 1052 | destroy_workqueue(cx->out_work_queue); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1053 | err: |
| 1054 | if (retval == 0) |
| 1055 | retval = -ENODEV; |
| 1056 | CX18_ERR("Error %d on initialization\n", retval); |
| 1057 | |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1058 | v4l2_device_unregister(&cx->v4l2_dev); |
| 1059 | kfree(cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1060 | return retval; |
| 1061 | } |
| 1062 | |
| 1063 | int cx18_init_on_first_open(struct cx18 *cx) |
| 1064 | { |
| 1065 | int video_input; |
| 1066 | int fw_retry_count = 3; |
| 1067 | struct v4l2_frequency vf; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1068 | struct cx18_open_id fh; |
| 1069 | |
| 1070 | fh.cx = cx; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1071 | |
| 1072 | if (test_bit(CX18_F_I_FAILED, &cx->i_flags)) |
| 1073 | return -ENXIO; |
| 1074 | |
| 1075 | if (test_and_set_bit(CX18_F_I_INITED, &cx->i_flags)) |
| 1076 | return 0; |
| 1077 | |
| 1078 | while (--fw_retry_count > 0) { |
| 1079 | /* load firmware */ |
| 1080 | if (cx18_firmware_init(cx) == 0) |
| 1081 | break; |
| 1082 | if (fw_retry_count > 1) |
| 1083 | CX18_WARN("Retry loading firmware\n"); |
| 1084 | } |
| 1085 | |
| 1086 | if (fw_retry_count == 0) { |
| 1087 | set_bit(CX18_F_I_FAILED, &cx->i_flags); |
| 1088 | return -ENXIO; |
| 1089 | } |
| 1090 | set_bit(CX18_F_I_LOADED_FW, &cx->i_flags); |
| 1091 | |
Andy Walls | 350145a | 2009-01-04 21:51:17 -0300 | [diff] [blame] | 1092 | /* |
| 1093 | * Init the firmware twice to work around a silicon bug |
| 1094 | * with the digital TS. |
| 1095 | * |
| 1096 | * The second firmware load requires us to normalize the APU state, |
| 1097 | * or the audio for the first analog capture will be badly incorrect. |
| 1098 | * |
| 1099 | * I can't seem to call APU_RESETAI and have it succeed without the |
| 1100 | * APU capturing audio, so we start and stop it here to do the reset |
| 1101 | */ |
| 1102 | |
| 1103 | /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */ |
| 1104 | cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0); |
| 1105 | cx18_vapi(cx, CX18_APU_RESETAI, 0); |
| 1106 | cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1107 | |
| 1108 | fw_retry_count = 3; |
| 1109 | while (--fw_retry_count > 0) { |
| 1110 | /* load firmware */ |
| 1111 | if (cx18_firmware_init(cx) == 0) |
| 1112 | break; |
| 1113 | if (fw_retry_count > 1) |
| 1114 | CX18_WARN("Retry loading firmware\n"); |
| 1115 | } |
| 1116 | |
| 1117 | if (fw_retry_count == 0) { |
| 1118 | set_bit(CX18_F_I_FAILED, &cx->i_flags); |
| 1119 | return -ENXIO; |
| 1120 | } |
| 1121 | |
Andy Walls | d5c02f6 | 2009-01-30 22:48:40 -0300 | [diff] [blame] | 1122 | /* |
| 1123 | * The second firmware load requires us to normalize the APU state, |
| 1124 | * or the audio for the first analog capture will be badly incorrect. |
| 1125 | * |
| 1126 | * I can't seem to call APU_RESETAI and have it succeed without the |
| 1127 | * APU capturing audio, so we start and stop it here to do the reset |
| 1128 | */ |
| 1129 | |
| 1130 | /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */ |
| 1131 | cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0); |
| 1132 | cx18_vapi(cx, CX18_APU_RESETAI, 0); |
| 1133 | cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG); |
| 1134 | |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 1135 | /* Init the A/V decoder, if it hasn't been already */ |
Hans Verkuil | cc26b07 | 2009-03-29 19:20:26 -0300 | [diff] [blame] | 1136 | v4l2_subdev_call(cx->sd_av, core, load_fw); |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 1137 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1138 | vf.tuner = 0; |
| 1139 | vf.type = V4L2_TUNER_ANALOG_TV; |
| 1140 | vf.frequency = 6400; /* the tuner 'baseline' frequency */ |
| 1141 | |
| 1142 | /* Set initial frequency. For PAL/SECAM broadcasts no |
| 1143 | 'default' channel exists AFAIK. */ |
| 1144 | if (cx->std == V4L2_STD_NTSC_M_JP) |
| 1145 | vf.frequency = 1460; /* ch. 1 91250*16/1000 */ |
| 1146 | else if (cx->std & V4L2_STD_NTSC_M) |
| 1147 | vf.frequency = 1076; /* ch. 4 67250*16/1000 */ |
| 1148 | |
| 1149 | video_input = cx->active_input; |
| 1150 | cx->active_input++; /* Force update of input */ |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1151 | cx18_s_input(NULL, &fh, video_input); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1152 | |
| 1153 | /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code |
| 1154 | in one place. */ |
| 1155 | cx->std++; /* Force full standard initialization */ |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 1156 | cx18_s_std(NULL, &fh, &cx->tuner_std); |
| 1157 | cx18_s_frequency(NULL, &fh, &vf); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1158 | return 0; |
| 1159 | } |
| 1160 | |
Andy Walls | deed75e | 2009-04-13 22:22:40 -0300 | [diff] [blame] | 1161 | static void cx18_cancel_in_work_orders(struct cx18 *cx) |
Andy Walls | 18b5dc2 | 2008-11-16 17:15:01 -0300 | [diff] [blame] | 1162 | { |
| 1163 | int i; |
Andy Walls | deed75e | 2009-04-13 22:22:40 -0300 | [diff] [blame] | 1164 | for (i = 0; i < CX18_MAX_IN_WORK_ORDERS; i++) |
| 1165 | cancel_work_sync(&cx->in_work_order[i].work); |
Andy Walls | 18b5dc2 | 2008-11-16 17:15:01 -0300 | [diff] [blame] | 1166 | } |
| 1167 | |
Andy Walls | 21a278b | 2009-04-15 20:45:10 -0300 | [diff] [blame] | 1168 | static void cx18_cancel_out_work_orders(struct cx18 *cx) |
| 1169 | { |
| 1170 | int i; |
| 1171 | for (i = 0; i < CX18_MAX_STREAMS; i++) |
| 1172 | if (&cx->streams[i].video_dev != NULL) |
| 1173 | cancel_work_sync(&cx->streams[i].out_work_order); |
| 1174 | } |
| 1175 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1176 | static void cx18_remove(struct pci_dev *pci_dev) |
| 1177 | { |
Andy Walls | 888cdb0 | 2009-01-11 15:08:53 -0300 | [diff] [blame] | 1178 | struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1179 | struct cx18 *cx = to_cx18(v4l2_dev); |
Andy Walls | 6da6bf5 | 2009-02-21 19:53:54 -0300 | [diff] [blame] | 1180 | int i; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1181 | |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1182 | CX18_DEBUG_INFO("Removing Card\n"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1183 | |
| 1184 | /* Stop all captures */ |
| 1185 | CX18_DEBUG_INFO("Stopping all streams\n"); |
Hans Verkuil | 31554ae | 2008-05-25 11:21:27 -0300 | [diff] [blame] | 1186 | if (atomic_read(&cx->tot_capturing) > 0) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1187 | cx18_stop_all_captures(cx); |
| 1188 | |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 1189 | /* Stop interrupts that cause incoming work to be queued */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 1190 | cx18_sw1_irq_disable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU); |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 1191 | |
| 1192 | /* Incoming work can cause outgoing work, so clean up incoming first */ |
| 1193 | cx18_cancel_in_work_orders(cx); |
Andy Walls | 21a278b | 2009-04-15 20:45:10 -0300 | [diff] [blame] | 1194 | cx18_cancel_out_work_orders(cx); |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 1195 | |
| 1196 | /* Stop ack interrupts that may have been needed for work to finish */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 1197 | cx18_sw2_irq_disable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1198 | |
| 1199 | cx18_halt_firmware(cx); |
| 1200 | |
Andy Walls | deed75e | 2009-04-13 22:22:40 -0300 | [diff] [blame] | 1201 | destroy_workqueue(cx->in_work_queue); |
Andy Walls | 8711615 | 2009-04-13 22:42:43 -0300 | [diff] [blame] | 1202 | destroy_workqueue(cx->out_work_queue); |
Andy Walls | 572bfea | 2008-11-25 21:43:05 -0300 | [diff] [blame] | 1203 | |
Hans Verkuil | 3f98387 | 2008-05-01 10:31:12 -0300 | [diff] [blame] | 1204 | cx18_streams_cleanup(cx, 1); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1205 | |
| 1206 | exit_cx18_i2c(cx); |
| 1207 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 1208 | free_irq(cx->pci_dev->irq, (void *)cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1209 | |
Hans Verkuil | cba627a | 2008-05-12 14:48:26 -0300 | [diff] [blame] | 1210 | cx18_iounmap(cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1211 | |
| 1212 | release_mem_region(cx->base_addr, CX18_MEM_SIZE); |
| 1213 | |
Andy Walls | 3d05913 | 2009-01-10 21:54:39 -0300 | [diff] [blame] | 1214 | pci_disable_device(cx->pci_dev); |
Andy Walls | 6da6bf5 | 2009-02-21 19:53:54 -0300 | [diff] [blame] | 1215 | |
| 1216 | if (cx->vbi.sliced_mpeg_data[0] != NULL) |
| 1217 | for (i = 0; i < CX18_VBI_FRAMES; i++) |
| 1218 | kfree(cx->vbi.sliced_mpeg_data[i]); |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1219 | |
| 1220 | CX18_INFO("Removed %s\n", cx->card_name); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1221 | |
Andy Walls | 888cdb0 | 2009-01-11 15:08:53 -0300 | [diff] [blame] | 1222 | v4l2_device_unregister(v4l2_dev); |
Andy Walls | 5811cf9 | 2009-02-14 17:08:37 -0300 | [diff] [blame] | 1223 | kfree(cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | /* define a pci_driver for card detection */ |
| 1227 | static struct pci_driver cx18_pci_driver = { |
| 1228 | .name = "cx18", |
| 1229 | .id_table = cx18_pci_tbl, |
| 1230 | .probe = cx18_probe, |
| 1231 | .remove = cx18_remove, |
| 1232 | }; |
| 1233 | |
Peter Huewe | 9710e7a | 2009-11-04 15:28:33 -0300 | [diff] [blame] | 1234 | static int __init module_start(void) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1235 | { |
| 1236 | printk(KERN_INFO "cx18: Start initialization, version %s\n", CX18_VERSION); |
| 1237 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1238 | /* Validate parameters */ |
| 1239 | if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) { |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 1240 | printk(KERN_ERR "cx18: Exiting, cx18_first_minor must be between 0 and %d\n", |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1241 | CX18_MAX_CARDS - 1); |
| 1242 | return -1; |
| 1243 | } |
| 1244 | |
| 1245 | if (cx18_debug < 0 || cx18_debug > 511) { |
| 1246 | cx18_debug = 0; |
| 1247 | printk(KERN_INFO "cx18: Debug value must be >= 0 and <= 511!\n"); |
| 1248 | } |
| 1249 | |
| 1250 | if (pci_register_driver(&cx18_pci_driver)) { |
| 1251 | printk(KERN_ERR "cx18: Error detecting PCI card\n"); |
| 1252 | return -ENODEV; |
| 1253 | } |
| 1254 | printk(KERN_INFO "cx18: End initialization\n"); |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
Peter Huewe | 9710e7a | 2009-11-04 15:28:33 -0300 | [diff] [blame] | 1258 | static void __exit module_cleanup(void) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1259 | { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1260 | pci_unregister_driver(&cx18_pci_driver); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | module_init(module_start); |
| 1264 | module_exit(module_cleanup); |