Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * budget-av.c: driver for the SAA7146 based Budget DVB cards |
| 3 | * with analog video in |
| 4 | * |
| 5 | * Compiled from various sources by Michael Hunold <michael@mihu.de> |
| 6 | * |
| 7 | * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> & |
| 8 | * Andrew de Quincey <adq_dvb@lidskialf.net> |
| 9 | * |
| 10 | * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de> |
| 11 | * |
| 12 | * Copyright (C) 1999-2002 Ralph Metzler |
| 13 | * & Marcus Metzler for convergence integrated media GmbH |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version 2 |
| 18 | * of the License, or (at your option) any later version. |
| 19 | * |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 30 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html |
| 31 | * |
| 32 | * |
| 33 | * the project's page is at http://www.linuxtv.org/dvb/ |
| 34 | */ |
| 35 | |
| 36 | #include "budget.h" |
| 37 | #include "stv0299.h" |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 38 | #include "tda1002x.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "tda1004x.h" |
Andrew de Quincey | 1c72cfdce | 2006-09-05 17:58:20 -0300 | [diff] [blame] | 40 | #include "tua6100.h" |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 41 | #include "dvb-pll.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <media/saa7146_vv.h> |
| 43 | #include <linux/module.h> |
| 44 | #include <linux/errno.h> |
| 45 | #include <linux/slab.h> |
| 46 | #include <linux/interrupt.h> |
| 47 | #include <linux/input.h> |
| 48 | #include <linux/spinlock.h> |
| 49 | |
| 50 | #include "dvb_ca_en50221.h" |
| 51 | |
| 52 | #define DEBICICAM 0x02420000 |
| 53 | |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 54 | #define SLOTSTATUS_NONE 1 |
| 55 | #define SLOTSTATUS_PRESENT 2 |
| 56 | #define SLOTSTATUS_RESET 4 |
| 57 | #define SLOTSTATUS_READY 8 |
| 58 | #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY) |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct budget_av { |
| 61 | struct budget budget; |
| 62 | struct video_device *vd; |
| 63 | int cur_input; |
| 64 | int has_saa7113; |
| 65 | struct tasklet_struct ciintf_irq_tasklet; |
| 66 | int slot_status; |
| 67 | struct dvb_ca_en50221 ca; |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 68 | u8 reinitialise_demod:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 71 | static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot); |
| 72 | |
| 73 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 74 | /* GPIO Connections: |
| 75 | * 0 - Vcc/Reset (Reset is controlled by capacitor). Resets the frontend *AS WELL*! |
| 76 | * 1 - CI memory select 0=>IO memory, 1=>Attribute Memory |
| 77 | * 2 - CI Card Enable (Active Low) |
| 78 | * 3 - CI Card Detect |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 79 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /**************************************************************************** |
| 82 | * INITIALIZATION |
| 83 | ****************************************************************************/ |
| 84 | |
| 85 | static u8 i2c_readreg(struct i2c_adapter *i2c, u8 id, u8 reg) |
| 86 | { |
| 87 | u8 mm1[] = { 0x00 }; |
| 88 | u8 mm2[] = { 0x00 }; |
| 89 | struct i2c_msg msgs[2]; |
| 90 | |
| 91 | msgs[0].flags = 0; |
| 92 | msgs[1].flags = I2C_M_RD; |
| 93 | msgs[0].addr = msgs[1].addr = id / 2; |
| 94 | mm1[0] = reg; |
| 95 | msgs[0].len = 1; |
| 96 | msgs[1].len = 1; |
| 97 | msgs[0].buf = mm1; |
| 98 | msgs[1].buf = mm2; |
| 99 | |
| 100 | i2c_transfer(i2c, msgs, 2); |
| 101 | |
| 102 | return mm2[0]; |
| 103 | } |
| 104 | |
| 105 | static int i2c_readregs(struct i2c_adapter *i2c, u8 id, u8 reg, u8 * buf, u8 len) |
| 106 | { |
| 107 | u8 mm1[] = { reg }; |
| 108 | struct i2c_msg msgs[2] = { |
| 109 | {.addr = id / 2,.flags = 0,.buf = mm1,.len = 1}, |
| 110 | {.addr = id / 2,.flags = I2C_M_RD,.buf = buf,.len = len} |
| 111 | }; |
| 112 | |
| 113 | if (i2c_transfer(i2c, msgs, 2) != 2) |
| 114 | return -EIO; |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static int i2c_writereg(struct i2c_adapter *i2c, u8 id, u8 reg, u8 val) |
| 120 | { |
| 121 | u8 msg[2] = { reg, val }; |
| 122 | struct i2c_msg msgs; |
| 123 | |
| 124 | msgs.flags = 0; |
| 125 | msgs.addr = id / 2; |
| 126 | msgs.len = 2; |
| 127 | msgs.buf = msg; |
| 128 | return i2c_transfer(i2c, &msgs, 1); |
| 129 | } |
| 130 | |
| 131 | static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address) |
| 132 | { |
| 133 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 134 | int result; |
| 135 | |
| 136 | if (slot != 0) |
| 137 | return -EINVAL; |
| 138 | |
| 139 | saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTHI); |
| 140 | udelay(1); |
| 141 | |
Andrew de Quincey | 2d0235d | 2006-01-09 15:25:05 -0200 | [diff] [blame] | 142 | result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 0xfff, 1, 0, 1); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 143 | if (result == -ETIMEDOUT) { |
| 144 | ciintf_slot_shutdown(ca, slot); |
| 145 | printk(KERN_INFO "budget-av: cam ejected 1\n"); |
| 146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return result; |
| 148 | } |
| 149 | |
| 150 | static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value) |
| 151 | { |
| 152 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 153 | int result; |
| 154 | |
| 155 | if (slot != 0) |
| 156 | return -EINVAL; |
| 157 | |
| 158 | saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTHI); |
| 159 | udelay(1); |
| 160 | |
Andrew de Quincey | 2d0235d | 2006-01-09 15:25:05 -0200 | [diff] [blame] | 161 | result = ttpci_budget_debiwrite(&budget_av->budget, DEBICICAM, address & 0xfff, 1, value, 0, 1); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 162 | if (result == -ETIMEDOUT) { |
| 163 | ciintf_slot_shutdown(ca, slot); |
| 164 | printk(KERN_INFO "budget-av: cam ejected 2\n"); |
| 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | return result; |
| 167 | } |
| 168 | |
| 169 | static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address) |
| 170 | { |
| 171 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 172 | int result; |
| 173 | |
| 174 | if (slot != 0) |
| 175 | return -EINVAL; |
| 176 | |
| 177 | saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO); |
| 178 | udelay(1); |
| 179 | |
| 180 | result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 3, 1, 0, 0); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 181 | if ((result == -ETIMEDOUT) || ((result == 0xff) && ((address & 3) < 2))) { |
| 182 | ciintf_slot_shutdown(ca, slot); |
| 183 | printk(KERN_INFO "budget-av: cam ejected 3\n"); |
| 184 | return -ETIMEDOUT; |
| 185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | return result; |
| 187 | } |
| 188 | |
| 189 | static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value) |
| 190 | { |
| 191 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 192 | int result; |
| 193 | |
| 194 | if (slot != 0) |
| 195 | return -EINVAL; |
| 196 | |
| 197 | saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO); |
| 198 | udelay(1); |
| 199 | |
| 200 | result = ttpci_budget_debiwrite(&budget_av->budget, DEBICICAM, address & 3, 1, value, 0, 0); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 201 | if (result == -ETIMEDOUT) { |
| 202 | ciintf_slot_shutdown(ca, slot); |
| 203 | printk(KERN_INFO "budget-av: cam ejected 5\n"); |
| 204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return result; |
| 206 | } |
| 207 | |
| 208 | static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot) |
| 209 | { |
| 210 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 211 | struct saa7146_dev *saa = budget_av->budget.dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | if (slot != 0) |
| 214 | return -EINVAL; |
| 215 | |
| 216 | dprintk(1, "ciintf_slot_reset\n"); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 217 | budget_av->slot_status = SLOTSTATUS_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 219 | saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 221 | saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); /* Vcc off */ |
| 222 | msleep(2); |
| 223 | saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO); /* Vcc on */ |
| 224 | msleep(20); /* 20 ms Vcc settling time */ |
| 225 | |
| 226 | saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTLO); /* enable card */ |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 227 | ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB); |
| 228 | msleep(20); |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 229 | |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 230 | /* reinitialise the frontend if necessary */ |
| 231 | if (budget_av->reinitialise_demod) |
| 232 | dvb_frontend_reinitialise(budget_av->budget.dvb_frontend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) |
| 238 | { |
| 239 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 240 | struct saa7146_dev *saa = budget_av->budget.dev; |
| 241 | |
| 242 | if (slot != 0) |
| 243 | return -EINVAL; |
| 244 | |
| 245 | dprintk(1, "ciintf_slot_shutdown\n"); |
| 246 | |
| 247 | ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 248 | budget_av->slot_status = SLOTSTATUS_NONE; |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) |
| 254 | { |
| 255 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 256 | struct saa7146_dev *saa = budget_av->budget.dev; |
| 257 | |
| 258 | if (slot != 0) |
| 259 | return -EINVAL; |
| 260 | |
| 261 | dprintk(1, "ciintf_slot_ts_enable: %d\n", budget_av->slot_status); |
| 262 | |
| 263 | ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open) |
| 269 | { |
| 270 | struct budget_av *budget_av = (struct budget_av *) ca->data; |
| 271 | struct saa7146_dev *saa = budget_av->budget.dev; |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 272 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | if (slot != 0) |
| 275 | return -EINVAL; |
| 276 | |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 277 | /* test the card detect line - needs to be done carefully |
| 278 | * since it never goes high for some CAMs on this interface (e.g. topuptv) */ |
| 279 | if (budget_av->slot_status == SLOTSTATUS_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); |
| 281 | udelay(1); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 282 | if (saa7146_read(saa, PSR) & MASK_06) { |
| 283 | if (budget_av->slot_status == SLOTSTATUS_NONE) { |
| 284 | budget_av->slot_status = SLOTSTATUS_PRESENT; |
| 285 | printk(KERN_INFO "budget-av: cam inserted A\n"); |
Andrew de Quincey | 2d0235d | 2006-01-09 15:25:05 -0200 | [diff] [blame] | 286 | } |
| 287 | } |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 288 | saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO); |
| 289 | } |
Andrew de Quincey | 2d0235d | 2006-01-09 15:25:05 -0200 | [diff] [blame] | 290 | |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 291 | /* We also try and read from IO memory to work round the above detection bug. If |
| 292 | * there is no CAM, we will get a timeout. Only done if there is no cam |
| 293 | * present, since this test actually breaks some cams :( |
| 294 | * |
| 295 | * if the CI interface is not open, we also do the above test since we |
| 296 | * don't care if the cam has problems - we'll be resetting it on open() anyway */ |
| 297 | if ((budget_av->slot_status == SLOTSTATUS_NONE) || (!open)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO); |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 299 | result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, 0, 1, 0, 1); |
| 300 | if ((result >= 0) && (budget_av->slot_status == SLOTSTATUS_NONE)) { |
| 301 | budget_av->slot_status = SLOTSTATUS_PRESENT; |
| 302 | printk(KERN_INFO "budget-av: cam inserted B\n"); |
| 303 | } else if (result < 0) { |
| 304 | if (budget_av->slot_status != SLOTSTATUS_NONE) { |
| 305 | ciintf_slot_shutdown(ca, slot); |
| 306 | printk(KERN_INFO "budget-av: cam ejected 5\n"); |
| 307 | return 0; |
| 308 | } |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 312 | /* read from attribute memory in reset/ready state to know when the CAM is ready */ |
| 313 | if (budget_av->slot_status == SLOTSTATUS_RESET) { |
| 314 | result = ciintf_read_attribute_mem(ca, slot, 0); |
| 315 | if (result == 0x1d) { |
| 316 | budget_av->slot_status = SLOTSTATUS_READY; |
| 317 | } |
| 318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 320 | /* work out correct return code */ |
| 321 | if (budget_av->slot_status != SLOTSTATUS_NONE) { |
| 322 | if (budget_av->slot_status & SLOTSTATUS_READY) { |
| 323 | return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY; |
| 324 | } |
| 325 | return DVB_CA_EN50221_POLL_CAM_PRESENT; |
| 326 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static int ciintf_init(struct budget_av *budget_av) |
| 331 | { |
| 332 | struct saa7146_dev *saa = budget_av->budget.dev; |
| 333 | int result; |
| 334 | |
| 335 | memset(&budget_av->ca, 0, sizeof(struct dvb_ca_en50221)); |
| 336 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 337 | saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO); |
| 338 | saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTLO); |
| 340 | saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO); |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /* Enable DEBI pins */ |
Hartmut Birr | 2a893de | 2006-12-03 21:08:08 -0300 | [diff] [blame] | 343 | saa7146_write(saa, MC1, MASK_27 | MASK_11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | /* register CI interface */ |
| 346 | budget_av->ca.owner = THIS_MODULE; |
| 347 | budget_av->ca.read_attribute_mem = ciintf_read_attribute_mem; |
| 348 | budget_av->ca.write_attribute_mem = ciintf_write_attribute_mem; |
| 349 | budget_av->ca.read_cam_control = ciintf_read_cam_control; |
| 350 | budget_av->ca.write_cam_control = ciintf_write_cam_control; |
| 351 | budget_av->ca.slot_reset = ciintf_slot_reset; |
| 352 | budget_av->ca.slot_shutdown = ciintf_slot_shutdown; |
| 353 | budget_av->ca.slot_ts_enable = ciintf_slot_ts_enable; |
| 354 | budget_av->ca.poll_slot_status = ciintf_poll_slot_status; |
| 355 | budget_av->ca.data = budget_av; |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 356 | budget_av->budget.ci_present = 1; |
| 357 | budget_av->slot_status = SLOTSTATUS_NONE; |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 358 | |
Johannes Stezenbach | fdc53a6 | 2005-05-16 21:54:39 -0700 | [diff] [blame] | 359 | if ((result = dvb_ca_en50221_init(&budget_av->budget.dvb_adapter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | &budget_av->ca, 0, 1)) != 0) { |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 361 | printk(KERN_ERR "budget-av: ci initialisation failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | goto error; |
| 363 | } |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 364 | |
| 365 | printk(KERN_INFO "budget-av: ci interface initialised.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return 0; |
| 367 | |
| 368 | error: |
Hartmut Birr | 2a893de | 2006-12-03 21:08:08 -0300 | [diff] [blame] | 369 | saa7146_write(saa, MC1, MASK_27); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return result; |
| 371 | } |
| 372 | |
| 373 | static void ciintf_deinit(struct budget_av *budget_av) |
| 374 | { |
| 375 | struct saa7146_dev *saa = budget_av->budget.dev; |
| 376 | |
| 377 | saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT); |
| 378 | saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT); |
| 379 | saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT); |
| 380 | saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); |
| 381 | |
| 382 | /* release the CA device */ |
| 383 | dvb_ca_en50221_release(&budget_av->ca); |
| 384 | |
| 385 | /* disable DEBI pins */ |
Hartmut Birr | 2a893de | 2006-12-03 21:08:08 -0300 | [diff] [blame] | 386 | saa7146_write(saa, MC1, MASK_27); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | |
| 390 | static const u8 saa7113_tab[] = { |
| 391 | 0x01, 0x08, |
| 392 | 0x02, 0xc0, |
| 393 | 0x03, 0x33, |
| 394 | 0x04, 0x00, |
| 395 | 0x05, 0x00, |
| 396 | 0x06, 0xeb, |
| 397 | 0x07, 0xe0, |
| 398 | 0x08, 0x28, |
| 399 | 0x09, 0x00, |
| 400 | 0x0a, 0x80, |
| 401 | 0x0b, 0x47, |
| 402 | 0x0c, 0x40, |
| 403 | 0x0d, 0x00, |
| 404 | 0x0e, 0x01, |
| 405 | 0x0f, 0x44, |
| 406 | |
| 407 | 0x10, 0x08, |
| 408 | 0x11, 0x0c, |
| 409 | 0x12, 0x7b, |
| 410 | 0x13, 0x00, |
| 411 | 0x15, 0x00, 0x16, 0x00, 0x17, 0x00, |
| 412 | |
| 413 | 0x57, 0xff, |
| 414 | 0x40, 0x82, 0x58, 0x00, 0x59, 0x54, 0x5a, 0x07, |
| 415 | 0x5b, 0x83, 0x5e, 0x00, |
| 416 | 0xff |
| 417 | }; |
| 418 | |
| 419 | static int saa7113_init(struct budget_av *budget_av) |
| 420 | { |
| 421 | struct budget *budget = &budget_av->budget; |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 422 | struct saa7146_dev *saa = budget->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | const u8 *data = saa7113_tab; |
| 424 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 425 | saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); |
| 426 | msleep(200); |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if (i2c_writereg(&budget->i2c_adap, 0x4a, 0x01, 0x08) != 1) { |
| 429 | dprintk(1, "saa7113 not found on KNC card\n"); |
| 430 | return -ENODEV; |
| 431 | } |
| 432 | |
| 433 | dprintk(1, "saa7113 detected and initializing\n"); |
| 434 | |
| 435 | while (*data != 0xff) { |
| 436 | i2c_writereg(&budget->i2c_adap, 0x4a, *data, *(data + 1)); |
| 437 | data += 2; |
| 438 | } |
| 439 | |
| 440 | dprintk(1, "saa7113 status=%02x\n", i2c_readreg(&budget->i2c_adap, 0x4a, 0x1f)); |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int saa7113_setinput(struct budget_av *budget_av, int input) |
| 446 | { |
| 447 | struct budget *budget = &budget_av->budget; |
| 448 | |
| 449 | if (1 != budget_av->has_saa7113) |
| 450 | return -ENODEV; |
| 451 | |
| 452 | if (input == 1) { |
| 453 | i2c_writereg(&budget->i2c_adap, 0x4a, 0x02, 0xc7); |
| 454 | i2c_writereg(&budget->i2c_adap, 0x4a, 0x09, 0x80); |
| 455 | } else if (input == 0) { |
| 456 | i2c_writereg(&budget->i2c_adap, 0x4a, 0x02, 0xc0); |
| 457 | i2c_writereg(&budget->i2c_adap, 0x4a, 0x09, 0x00); |
| 458 | } else |
| 459 | return -EINVAL; |
| 460 | |
| 461 | budget_av->cur_input = input; |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | |
| 466 | static int philips_su1278_ty_ci_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio) |
| 467 | { |
| 468 | u8 aclk = 0; |
| 469 | u8 bclk = 0; |
| 470 | u8 m1; |
| 471 | |
| 472 | aclk = 0xb5; |
| 473 | if (srate < 2000000) |
| 474 | bclk = 0x86; |
| 475 | else if (srate < 5000000) |
| 476 | bclk = 0x89; |
| 477 | else if (srate < 15000000) |
| 478 | bclk = 0x8f; |
| 479 | else if (srate < 45000000) |
| 480 | bclk = 0x95; |
| 481 | |
| 482 | m1 = 0x14; |
| 483 | if (srate < 4000000) |
| 484 | m1 = 0x10; |
| 485 | |
| 486 | stv0299_writereg(fe, 0x13, aclk); |
| 487 | stv0299_writereg(fe, 0x14, bclk); |
| 488 | stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff); |
| 489 | stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff); |
| 490 | stv0299_writereg(fe, 0x21, (ratio) & 0xf0); |
| 491 | stv0299_writereg(fe, 0x0f, 0x80 | m1); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 496 | static int philips_su1278_ty_ci_tuner_set_params(struct dvb_frontend *fe, |
| 497 | struct dvb_frontend_parameters *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | u32 div; |
| 500 | u8 buf[4]; |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 501 | struct budget *budget = (struct budget *) fe->dvb->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) }; |
| 503 | |
| 504 | if ((params->frequency < 950000) || (params->frequency > 2150000)) |
| 505 | return -EINVAL; |
| 506 | |
| 507 | div = (params->frequency + (125 - 1)) / 125; // round correctly |
| 508 | buf[0] = (div >> 8) & 0x7f; |
| 509 | buf[1] = div & 0xff; |
| 510 | buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4; |
| 511 | buf[3] = 0x20; |
| 512 | |
| 513 | if (params->u.qpsk.symbol_rate < 4000000) |
| 514 | buf[3] |= 1; |
| 515 | |
| 516 | if (params->frequency < 1250000) |
| 517 | buf[3] |= 0; |
| 518 | else if (params->frequency < 1550000) |
| 519 | buf[3] |= 0x40; |
| 520 | else if (params->frequency < 2050000) |
| 521 | buf[3] |= 0x80; |
| 522 | else if (params->frequency < 2150000) |
| 523 | buf[3] |= 0xC0; |
| 524 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 525 | if (fe->ops.i2c_gate_ctrl) |
| 526 | fe->ops.i2c_gate_ctrl(fe, 1); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 527 | if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return -EIO; |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static u8 typhoon_cinergy1200s_inittab[] = { |
| 533 | 0x01, 0x15, |
| 534 | 0x02, 0x30, |
| 535 | 0x03, 0x00, |
| 536 | 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ |
| 537 | 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ |
| 538 | 0x06, 0x40, /* DAC not used, set to high impendance mode */ |
| 539 | 0x07, 0x00, /* DAC LSB */ |
| 540 | 0x08, 0x40, /* DiSEqC off */ |
| 541 | 0x09, 0x00, /* FIFO */ |
| 542 | 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ |
| 543 | 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ |
| 544 | 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ |
| 545 | 0x10, 0x3f, // AGC2 0x3d |
| 546 | 0x11, 0x84, |
Oliver Endriss | ff29d06 | 2005-11-08 21:35:43 -0800 | [diff] [blame] | 547 | 0x12, 0xb9, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | 0x15, 0xc9, // lock detector threshold |
| 549 | 0x16, 0x00, |
| 550 | 0x17, 0x00, |
| 551 | 0x18, 0x00, |
| 552 | 0x19, 0x00, |
| 553 | 0x1a, 0x00, |
| 554 | 0x1f, 0x50, |
| 555 | 0x20, 0x00, |
| 556 | 0x21, 0x00, |
| 557 | 0x22, 0x00, |
| 558 | 0x23, 0x00, |
| 559 | 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 |
| 560 | 0x29, 0x1e, // 1/2 threshold |
| 561 | 0x2a, 0x14, // 2/3 threshold |
| 562 | 0x2b, 0x0f, // 3/4 threshold |
| 563 | 0x2c, 0x09, // 5/6 threshold |
| 564 | 0x2d, 0x05, // 7/8 threshold |
| 565 | 0x2e, 0x01, |
| 566 | 0x31, 0x1f, // test all FECs |
| 567 | 0x32, 0x19, // viterbi and synchro search |
| 568 | 0x33, 0xfc, // rs control |
| 569 | 0x34, 0x93, // error control |
| 570 | 0x0f, 0x92, |
| 571 | 0xff, 0xff |
| 572 | }; |
| 573 | |
| 574 | static struct stv0299_config typhoon_config = { |
| 575 | .demod_address = 0x68, |
| 576 | .inittab = typhoon_cinergy1200s_inittab, |
| 577 | .mclk = 88000000UL, |
| 578 | .invert = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | .skip_reinit = 0, |
| 580 | .lock_output = STV0229_LOCKOUTPUT_1, |
| 581 | .volt13_op0_op1 = STV0299_VOLT13_OP0, |
| 582 | .min_delay_ms = 100, |
| 583 | .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | |
| 587 | static struct stv0299_config cinergy_1200s_config = { |
| 588 | .demod_address = 0x68, |
| 589 | .inittab = typhoon_cinergy1200s_inittab, |
| 590 | .mclk = 88000000UL, |
| 591 | .invert = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | .skip_reinit = 0, |
| 593 | .lock_output = STV0229_LOCKOUTPUT_0, |
| 594 | .volt13_op0_op1 = STV0299_VOLT13_OP0, |
| 595 | .min_delay_ms = 100, |
| 596 | .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | }; |
| 598 | |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 599 | static struct stv0299_config cinergy_1200s_1894_0010_config = { |
| 600 | .demod_address = 0x68, |
| 601 | .inittab = typhoon_cinergy1200s_inittab, |
| 602 | .mclk = 88000000UL, |
| 603 | .invert = 1, |
| 604 | .skip_reinit = 0, |
| 605 | .lock_output = STV0229_LOCKOUTPUT_1, |
| 606 | .volt13_op0_op1 = STV0299_VOLT13_OP0, |
| 607 | .min_delay_ms = 100, |
| 608 | .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 609 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 611 | static int philips_cu1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
| 613 | struct budget *budget = (struct budget *) fe->dvb->priv; |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 614 | u8 buf[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) }; |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 616 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 618 | #define CU1216_IF 36125000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | #define TUNER_MUL 62500 |
| 620 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 621 | u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
| 623 | buf[0] = (div >> 8) & 0x7f; |
| 624 | buf[1] = div & 0xff; |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 625 | buf[2] = 0xce; |
Johannes Stezenbach | eef5764 | 2005-07-07 17:57:58 -0700 | [diff] [blame] | 626 | buf[3] = (params->frequency < 150000000 ? 0x01 : |
| 627 | params->frequency < 445000000 ? 0x02 : 0x04); |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 628 | buf[4] = 0xde; |
| 629 | buf[5] = 0x20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 631 | if (fe->ops.i2c_gate_ctrl) |
| 632 | fe->ops.i2c_gate_ctrl(fe, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1) |
| 634 | return -EIO; |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 635 | |
| 636 | /* wait for the pll lock */ |
| 637 | msg.flags = I2C_M_RD; |
| 638 | msg.len = 1; |
| 639 | for (i = 0; i < 20; i++) { |
| 640 | if (fe->ops.i2c_gate_ctrl) |
| 641 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 642 | if (i2c_transfer(&budget->i2c_adap, &msg, 1) == 1 && (buf[0] & 0x40)) |
| 643 | break; |
| 644 | msleep(10); |
| 645 | } |
| 646 | |
| 647 | /* switch the charge pump to the lower current */ |
| 648 | msg.flags = 0; |
| 649 | msg.len = 2; |
| 650 | msg.buf = &buf[2]; |
| 651 | buf[2] &= ~0x40; |
| 652 | if (fe->ops.i2c_gate_ctrl) |
| 653 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 654 | if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1) |
| 655 | return -EIO; |
| 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | return 0; |
| 658 | } |
| 659 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 660 | static struct tda1002x_config philips_cu1216_config = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | .demod_address = 0x0c, |
Hartmut Birr | dc120b0 | 2007-04-21 19:44:10 -0300 | [diff] [blame] | 662 | .invert = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | }; |
| 664 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 665 | static struct tda1002x_config philips_cu1216_config_altaddress = { |
Andrew de Quincey | 61cebe9 | 2006-11-19 14:10:59 -0300 | [diff] [blame] | 666 | .demod_address = 0x0d, |
Hartmut Birr | dc120b0 | 2007-04-21 19:44:10 -0300 | [diff] [blame] | 667 | .invert = 0, |
Andrew de Quincey | 61cebe9 | 2006-11-19 14:10:59 -0300 | [diff] [blame] | 668 | }; |
| 669 | |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 670 | static int philips_tu1216_tuner_init(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
| 672 | struct budget *budget = (struct budget *) fe->dvb->priv; |
| 673 | static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab }; |
| 674 | struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) }; |
| 675 | |
| 676 | // setup PLL configuration |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 677 | if (fe->ops.i2c_gate_ctrl) |
| 678 | fe->ops.i2c_gate_ctrl(fe, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) |
| 680 | return -EIO; |
| 681 | msleep(1); |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 686 | static int philips_tu1216_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | { |
| 688 | struct budget *budget = (struct budget *) fe->dvb->priv; |
| 689 | u8 tuner_buf[4]; |
| 690 | struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,.len = |
| 691 | sizeof(tuner_buf) }; |
| 692 | int tuner_frequency = 0; |
| 693 | u8 band, cp, filter; |
| 694 | |
| 695 | // determine charge pump |
| 696 | tuner_frequency = params->frequency + 36166000; |
| 697 | if (tuner_frequency < 87000000) |
| 698 | return -EINVAL; |
| 699 | else if (tuner_frequency < 130000000) |
| 700 | cp = 3; |
| 701 | else if (tuner_frequency < 160000000) |
| 702 | cp = 5; |
| 703 | else if (tuner_frequency < 200000000) |
| 704 | cp = 6; |
| 705 | else if (tuner_frequency < 290000000) |
| 706 | cp = 3; |
| 707 | else if (tuner_frequency < 420000000) |
| 708 | cp = 5; |
| 709 | else if (tuner_frequency < 480000000) |
| 710 | cp = 6; |
| 711 | else if (tuner_frequency < 620000000) |
| 712 | cp = 3; |
| 713 | else if (tuner_frequency < 830000000) |
| 714 | cp = 5; |
| 715 | else if (tuner_frequency < 895000000) |
| 716 | cp = 7; |
| 717 | else |
| 718 | return -EINVAL; |
| 719 | |
| 720 | // determine band |
| 721 | if (params->frequency < 49000000) |
| 722 | return -EINVAL; |
| 723 | else if (params->frequency < 161000000) |
| 724 | band = 1; |
| 725 | else if (params->frequency < 444000000) |
| 726 | band = 2; |
| 727 | else if (params->frequency < 861000000) |
| 728 | band = 4; |
| 729 | else |
| 730 | return -EINVAL; |
| 731 | |
| 732 | // setup PLL filter |
| 733 | switch (params->u.ofdm.bandwidth) { |
| 734 | case BANDWIDTH_6_MHZ: |
| 735 | filter = 0; |
| 736 | break; |
| 737 | |
| 738 | case BANDWIDTH_7_MHZ: |
| 739 | filter = 0; |
| 740 | break; |
| 741 | |
| 742 | case BANDWIDTH_8_MHZ: |
| 743 | filter = 1; |
| 744 | break; |
| 745 | |
| 746 | default: |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
| 750 | // calculate divisor |
| 751 | // ((36166000+((1000000/6)/2)) + Finput)/(1000000/6) |
| 752 | tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000; |
| 753 | |
| 754 | // setup tuner buffer |
| 755 | tuner_buf[0] = (tuner_frequency >> 8) & 0x7f; |
| 756 | tuner_buf[1] = tuner_frequency & 0xff; |
| 757 | tuner_buf[2] = 0xca; |
| 758 | tuner_buf[3] = (cp << 5) | (filter << 3) | band; |
| 759 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 760 | if (fe->ops.i2c_gate_ctrl) |
| 761 | fe->ops.i2c_gate_ctrl(fe, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) |
| 763 | return -EIO; |
| 764 | |
| 765 | msleep(1); |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | static int philips_tu1216_request_firmware(struct dvb_frontend *fe, |
| 770 | const struct firmware **fw, char *name) |
| 771 | { |
| 772 | struct budget *budget = (struct budget *) fe->dvb->priv; |
| 773 | |
| 774 | return request_firmware(fw, name, &budget->dev->pci->dev); |
| 775 | } |
| 776 | |
| 777 | static struct tda1004x_config philips_tu1216_config = { |
| 778 | |
| 779 | .demod_address = 0x8, |
| 780 | .invert = 1, |
| 781 | .invert_oclk = 1, |
Hartmut Hackmann | ecb60de | 2005-07-07 17:57:40 -0700 | [diff] [blame] | 782 | .xtal_freq = TDA10046_XTAL_4M, |
| 783 | .agc_config = TDA10046_AGC_DEFAULT, |
| 784 | .if_freq = TDA10046_FREQ_3617, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | .request_firmware = philips_tu1216_request_firmware, |
| 786 | }; |
| 787 | |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 788 | static u8 philips_sd1878_inittab[] = { |
| 789 | 0x01, 0x15, |
| 790 | 0x02, 0x30, |
| 791 | 0x03, 0x00, |
| 792 | 0x04, 0x7d, |
| 793 | 0x05, 0x35, |
| 794 | 0x06, 0x40, |
| 795 | 0x07, 0x00, |
| 796 | 0x08, 0x43, |
| 797 | 0x09, 0x02, |
| 798 | 0x0C, 0x51, |
| 799 | 0x0D, 0x82, |
| 800 | 0x0E, 0x23, |
| 801 | 0x10, 0x3f, |
| 802 | 0x11, 0x84, |
| 803 | 0x12, 0xb9, |
| 804 | 0x15, 0xc9, |
| 805 | 0x16, 0x19, |
| 806 | 0x17, 0x8c, |
| 807 | 0x18, 0x59, |
| 808 | 0x19, 0xf8, |
| 809 | 0x1a, 0xfe, |
| 810 | 0x1c, 0x7f, |
| 811 | 0x1d, 0x00, |
| 812 | 0x1e, 0x00, |
| 813 | 0x1f, 0x50, |
| 814 | 0x20, 0x00, |
| 815 | 0x21, 0x00, |
| 816 | 0x22, 0x00, |
| 817 | 0x23, 0x00, |
| 818 | 0x28, 0x00, |
| 819 | 0x29, 0x28, |
| 820 | 0x2a, 0x14, |
| 821 | 0x2b, 0x0f, |
| 822 | 0x2c, 0x09, |
| 823 | 0x2d, 0x09, |
| 824 | 0x31, 0x1f, |
| 825 | 0x32, 0x19, |
| 826 | 0x33, 0xfc, |
| 827 | 0x34, 0x93, |
| 828 | 0xff, 0xff |
| 829 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 831 | static int philips_sd1878_ci_set_symbol_rate(struct dvb_frontend *fe, |
| 832 | u32 srate, u32 ratio) |
| 833 | { |
| 834 | u8 aclk = 0; |
| 835 | u8 bclk = 0; |
| 836 | u8 m1; |
| 837 | |
| 838 | aclk = 0xb5; |
| 839 | if (srate < 2000000) |
| 840 | bclk = 0x86; |
| 841 | else if (srate < 5000000) |
| 842 | bclk = 0x89; |
| 843 | else if (srate < 15000000) |
| 844 | bclk = 0x8f; |
| 845 | else if (srate < 45000000) |
| 846 | bclk = 0x95; |
| 847 | |
| 848 | m1 = 0x14; |
| 849 | if (srate < 4000000) |
| 850 | m1 = 0x10; |
| 851 | |
| 852 | stv0299_writereg(fe, 0x0e, 0x23); |
| 853 | stv0299_writereg(fe, 0x0f, 0x94); |
| 854 | stv0299_writereg(fe, 0x10, 0x39); |
| 855 | stv0299_writereg(fe, 0x13, aclk); |
| 856 | stv0299_writereg(fe, 0x14, bclk); |
| 857 | stv0299_writereg(fe, 0x15, 0xc9); |
| 858 | stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff); |
| 859 | stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff); |
| 860 | stv0299_writereg(fe, 0x21, (ratio) & 0xf0); |
| 861 | stv0299_writereg(fe, 0x0f, 0x80 | m1); |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static struct stv0299_config philips_sd1878_config = { |
| 867 | .demod_address = 0x68, |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 868 | .inittab = philips_sd1878_inittab, |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 869 | .mclk = 88000000UL, |
| 870 | .invert = 0, |
| 871 | .skip_reinit = 0, |
| 872 | .lock_output = STV0229_LOCKOUTPUT_1, |
| 873 | .volt13_op0_op1 = STV0299_VOLT13_OP0, |
| 874 | .min_delay_ms = 100, |
| 875 | .set_symbol_rate = philips_sd1878_ci_set_symbol_rate, |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 876 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | static u8 read_pwm(struct budget_av *budget_av) |
| 879 | { |
| 880 | u8 b = 0xff; |
| 881 | u8 pwm; |
| 882 | struct i2c_msg msg[] = { {.addr = 0x50,.flags = 0,.buf = &b,.len = 1}, |
| 883 | {.addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} |
| 884 | }; |
| 885 | |
| 886 | if ((i2c_transfer(&budget_av->budget.i2c_adap, msg, 2) != 2) |
| 887 | || (pwm == 0xff)) |
| 888 | pwm = 0x48; |
| 889 | |
| 890 | return pwm; |
| 891 | } |
| 892 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 893 | #define SUBID_DVBS_KNC1 0x0010 |
| 894 | #define SUBID_DVBS_KNC1_PLUS 0x0011 |
| 895 | #define SUBID_DVBS_TYPHOON 0x4f56 |
| 896 | #define SUBID_DVBS_CINERGY1200 0x1154 |
| 897 | #define SUBID_DVBS_CYNERGY1200N 0x1155 |
| 898 | #define SUBID_DVBS_TV_STAR 0x0014 |
| 899 | #define SUBID_DVBS_TV_STAR_CI 0x0016 |
| 900 | #define SUBID_DVBS_EASYWATCH_1 0x001a |
| 901 | #define SUBID_DVBS_EASYWATCH 0x001e |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 902 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 903 | #define SUBID_DVBC_EASYWATCH 0x002a |
| 904 | #define SUBID_DVBC_EASYWATCH_MK3 0x002c |
| 905 | #define SUBID_DVBC_KNC1 0x0020 |
| 906 | #define SUBID_DVBC_KNC1_PLUS 0x0021 |
| 907 | #define SUBID_DVBC_KNC1_MK3 0x0022 |
| 908 | #define SUBID_DVBC_KNC1_PLUS_MK3 0x0023 |
| 909 | #define SUBID_DVBC_CINERGY1200 0x1156 |
| 910 | #define SUBID_DVBC_CINERGY1200_MK3 0x1176 |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 911 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 912 | #define SUBID_DVBT_KNC1_PLUS 0x0031 |
| 913 | #define SUBID_DVBT_KNC1 0x0030 |
| 914 | #define SUBID_DVBT_CINERGY1200 0x1157 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | static void frontend_init(struct budget_av *budget_av) |
| 917 | { |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 918 | struct saa7146_dev * saa = budget_av->budget.dev; |
| 919 | struct dvb_frontend * fe = NULL; |
| 920 | |
Andrew de Quincey | 473f542 | 2006-04-13 17:29:07 -0300 | [diff] [blame] | 921 | /* Enable / PowerON Frontend */ |
| 922 | saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO); |
| 923 | |
Hartmut Birr | 740cf9e | 2006-11-03 15:34:18 -0300 | [diff] [blame] | 924 | /* Wait for PowerON */ |
| 925 | msleep(100); |
| 926 | |
Andrew de Quincey | 473f542 | 2006-04-13 17:29:07 -0300 | [diff] [blame] | 927 | /* additional setup necessary for the PLUS cards */ |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 928 | switch (saa->pci->subsystem_device) { |
| 929 | case SUBID_DVBS_KNC1_PLUS: |
| 930 | case SUBID_DVBC_KNC1_PLUS: |
| 931 | case SUBID_DVBT_KNC1_PLUS: |
Thomas Hamm | c01d1e4 | 2006-11-17 07:12:58 -0300 | [diff] [blame] | 932 | case SUBID_DVBC_EASYWATCH: |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 933 | case SUBID_DVBC_KNC1_PLUS_MK3: |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 934 | saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTHI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | break; |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | switch (saa->pci->subsystem_device) { |
| 939 | |
| 940 | case SUBID_DVBS_KNC1: |
Christoph Pfister | 4e318be | 2006-08-12 09:13:35 -0300 | [diff] [blame] | 941 | case SUBID_DVBS_KNC1_PLUS: |
Lothar Englisch | 60110ce | 2006-06-06 16:13:46 -0300 | [diff] [blame] | 942 | case SUBID_DVBS_EASYWATCH_1: |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 943 | if (saa->pci->subsystem_vendor == 0x1894) { |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 944 | fe = dvb_attach(stv0299_attach, &cinergy_1200s_1894_0010_config, |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 945 | &budget_av->budget.i2c_adap); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 946 | if (fe) { |
Andrew de Quincey | 1c72cfdce | 2006-09-05 17:58:20 -0300 | [diff] [blame] | 947 | dvb_attach(tua6100_attach, fe, 0x60, &budget_av->budget.i2c_adap); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 948 | } |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 949 | } else { |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 950 | fe = dvb_attach(stv0299_attach, &typhoon_config, |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 951 | &budget_av->budget.i2c_adap); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 952 | if (fe) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 953 | fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params; |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 954 | } |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 955 | } |
| 956 | break; |
| 957 | |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 958 | case SUBID_DVBS_TV_STAR: |
| 959 | case SUBID_DVBS_TV_STAR_CI: |
| 960 | case SUBID_DVBS_CYNERGY1200N: |
Thilo Berger | 36f4f33 | 2006-02-27 00:09:08 -0300 | [diff] [blame] | 961 | case SUBID_DVBS_EASYWATCH: |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 962 | fe = dvb_attach(stv0299_attach, &philips_sd1878_config, |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 963 | &budget_av->budget.i2c_adap); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 964 | if (fe) { |
Michael Krufky | 9b98fd2 | 2007-05-07 01:48:56 -0300 | [diff] [blame^] | 965 | dvb_attach(dvb_pll_attach, fe, 0x60, |
| 966 | &budget_av->budget.i2c_adap, |
| 967 | &dvb_pll_philips_sd1878_tda8261); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 968 | } |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 969 | break; |
| 970 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 971 | case SUBID_DVBS_TYPHOON: |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 972 | fe = dvb_attach(stv0299_attach, &typhoon_config, |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 973 | &budget_av->budget.i2c_adap); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 974 | if (fe) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 975 | fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params; |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 976 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | break; |
| 978 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 979 | case SUBID_DVBS_CINERGY1200: |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 980 | fe = dvb_attach(stv0299_attach, &cinergy_1200s_config, |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 981 | &budget_av->budget.i2c_adap); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 982 | if (fe) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 983 | fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params; |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 984 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | break; |
| 986 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 987 | case SUBID_DVBC_KNC1: |
| 988 | case SUBID_DVBC_KNC1_PLUS: |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 989 | case SUBID_DVBC_CINERGY1200: |
Thomas Hamm | c01d1e4 | 2006-11-17 07:12:58 -0300 | [diff] [blame] | 990 | case SUBID_DVBC_EASYWATCH: |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 991 | budget_av->reinitialise_demod = 1; |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 992 | budget_av->budget.dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240; |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 993 | fe = dvb_attach(tda10021_attach, &philips_cu1216_config, |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 994 | &budget_av->budget.i2c_adap, |
| 995 | read_pwm(budget_av)); |
Andrew de Quincey | 61cebe9 | 2006-11-19 14:10:59 -0300 | [diff] [blame] | 996 | if (fe == NULL) |
| 997 | fe = dvb_attach(tda10021_attach, &philips_cu1216_config_altaddress, |
| 998 | &budget_av->budget.i2c_adap, |
| 999 | read_pwm(budget_av)); |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 1000 | if (fe) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1001 | fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set_params; |
Andrew de Quincey | e87d41c | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 1002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | break; |
| 1004 | |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 1005 | case SUBID_DVBC_EASYWATCH_MK3: |
| 1006 | case SUBID_DVBC_CINERGY1200_MK3: |
| 1007 | case SUBID_DVBC_KNC1_MK3: |
| 1008 | case SUBID_DVBC_KNC1_PLUS_MK3: |
| 1009 | budget_av->reinitialise_demod = 1; |
| 1010 | budget_av->budget.dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240; |
| 1011 | fe = dvb_attach(tda10023_attach, &philips_cu1216_config, |
| 1012 | &budget_av->budget.i2c_adap, |
| 1013 | read_pwm(budget_av)); |
| 1014 | if (fe) { |
| 1015 | fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set_params; |
| 1016 | } |
| 1017 | break; |
| 1018 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1019 | case SUBID_DVBT_KNC1: |
| 1020 | case SUBID_DVBT_KNC1_PLUS: |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1021 | case SUBID_DVBT_CINERGY1200: |
Andrew de Quincey | 5c1208b | 2006-05-22 10:32:02 -0300 | [diff] [blame] | 1022 | budget_av->reinitialise_demod = 1; |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 1023 | fe = dvb_attach(tda10046_attach, &philips_tu1216_config, |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1024 | &budget_av->budget.i2c_adap); |
Andrew de Quincey | 6b3ccab | 2006-04-20 12:01:47 -0300 | [diff] [blame] | 1025 | if (fe) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1026 | fe->ops.tuner_ops.init = philips_tu1216_tuner_init; |
| 1027 | fe->ops.tuner_ops.set_params = philips_tu1216_tuner_set_params; |
Andrew de Quincey | 6b3ccab | 2006-04-20 12:01:47 -0300 | [diff] [blame] | 1028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | break; |
| 1030 | } |
| 1031 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1032 | if (fe == NULL) { |
| 1033 | printk(KERN_ERR "budget-av: A frontend driver was not found " |
| 1034 | "for device %04x/%04x subsystem %04x/%04x\n", |
| 1035 | saa->pci->vendor, |
| 1036 | saa->pci->device, |
| 1037 | saa->pci->subsystem_vendor, |
| 1038 | saa->pci->subsystem_device); |
| 1039 | return; |
| 1040 | } |
| 1041 | |
| 1042 | budget_av->budget.dvb_frontend = fe; |
| 1043 | |
| 1044 | if (dvb_register_frontend(&budget_av->budget.dvb_adapter, |
| 1045 | budget_av->budget.dvb_frontend)) { |
| 1046 | printk(KERN_ERR "budget-av: Frontend registration failed!\n"); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 1047 | dvb_frontend_detach(budget_av->budget.dvb_frontend); |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1048 | budget_av->budget.dvb_frontend = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | static void budget_av_irq(struct saa7146_dev *dev, u32 * isr) |
| 1054 | { |
| 1055 | struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; |
| 1056 | |
| 1057 | dprintk(8, "dev: %p, budget_av: %p\n", dev, budget_av); |
| 1058 | |
| 1059 | if (*isr & MASK_10) |
| 1060 | ttpci_budget_irq10_handler(dev, isr); |
| 1061 | } |
| 1062 | |
| 1063 | static int budget_av_detach(struct saa7146_dev *dev) |
| 1064 | { |
| 1065 | struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; |
| 1066 | int err; |
| 1067 | |
| 1068 | dprintk(2, "dev: %p\n", dev); |
| 1069 | |
| 1070 | if (1 == budget_av->has_saa7113) { |
| 1071 | saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTLO); |
| 1072 | |
| 1073 | msleep(200); |
| 1074 | |
| 1075 | saa7146_unregister_device(&budget_av->vd, dev); |
Marco Schluessler | 716a4e3 | 2007-02-03 14:47:14 -0300 | [diff] [blame] | 1076 | |
| 1077 | saa7146_vv_release(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | if (budget_av->budget.ci_present) |
| 1081 | ciintf_deinit(budget_av); |
| 1082 | |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 1083 | if (budget_av->budget.dvb_frontend != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | dvb_unregister_frontend(budget_av->budget.dvb_frontend); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 1085 | dvb_frontend_detach(budget_av->budget.dvb_frontend); |
Andrew de Quincey | 2bfe031 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 1086 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | err = ttpci_budget_deinit(&budget_av->budget); |
| 1088 | |
| 1089 | kfree(budget_av); |
| 1090 | |
| 1091 | return err; |
| 1092 | } |
| 1093 | |
| 1094 | static struct saa7146_ext_vv vv_data; |
| 1095 | |
| 1096 | static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info) |
| 1097 | { |
| 1098 | struct budget_av *budget_av; |
| 1099 | u8 *mac; |
| 1100 | int err; |
| 1101 | |
| 1102 | dprintk(2, "dev: %p\n", dev); |
| 1103 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 1104 | if (!(budget_av = kzalloc(sizeof(struct budget_av), GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | return -ENOMEM; |
| 1106 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1107 | budget_av->has_saa7113 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | budget_av->budget.ci_present = 0; |
| 1109 | |
| 1110 | dev->ext_priv = budget_av; |
| 1111 | |
| 1112 | if ((err = ttpci_budget_init(&budget_av->budget, dev, info, THIS_MODULE))) { |
| 1113 | kfree(budget_av); |
| 1114 | return err; |
| 1115 | } |
| 1116 | |
| 1117 | /* knc1 initialization */ |
| 1118 | saa7146_write(dev, DD1_STREAM_B, 0x04000000); |
| 1119 | saa7146_write(dev, DD1_INIT, 0x07000600); |
| 1120 | saa7146_write(dev, MC2, MASK_09 | MASK_25 | MASK_10 | MASK_26); |
| 1121 | |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1122 | if (saa7113_init(budget_av) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | budget_av->has_saa7113 = 1; |
| 1124 | |
| 1125 | if (0 != saa7146_vv_init(dev, &vv_data)) { |
| 1126 | /* fixme: proper cleanup here */ |
| 1127 | ERR(("cannot init vv subsystem.\n")); |
| 1128 | return err; |
| 1129 | } |
| 1130 | |
| 1131 | if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) { |
| 1132 | /* fixme: proper cleanup here */ |
| 1133 | ERR(("cannot register capture v4l2 device.\n")); |
Marco Schluessler | 716a4e3 | 2007-02-03 14:47:14 -0300 | [diff] [blame] | 1134 | saa7146_vv_release(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | return err; |
| 1136 | } |
| 1137 | |
| 1138 | /* beware: this modifies dev->vv ... */ |
| 1139 | saa7146_set_hps_source_and_sync(dev, SAA7146_HPS_SOURCE_PORT_A, |
| 1140 | SAA7146_HPS_SYNC_PORT_A); |
| 1141 | |
| 1142 | saa7113_setinput(budget_av, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /* fixme: find some sane values here... */ |
| 1146 | saa7146_write(dev, PCI_BT_V1, 0x1c00101f); |
| 1147 | |
Johannes Stezenbach | fdc53a6 | 2005-05-16 21:54:39 -0700 | [diff] [blame] | 1148 | mac = budget_av->budget.dvb_adapter.proposed_mac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | if (i2c_readregs(&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) { |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1150 | printk(KERN_ERR "KNC1-%d: Could not read MAC from KNC1 card\n", |
Johannes Stezenbach | fdc53a6 | 2005-05-16 21:54:39 -0700 | [diff] [blame] | 1151 | budget_av->budget.dvb_adapter.num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | memset(mac, 0, 6); |
| 1153 | } else { |
Johannes Stezenbach | b82a96a | 2005-05-16 21:54:49 -0700 | [diff] [blame] | 1154 | printk(KERN_INFO "KNC1-%d: MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", |
Johannes Stezenbach | fdc53a6 | 2005-05-16 21:54:39 -0700 | [diff] [blame] | 1155 | budget_av->budget.dvb_adapter.num, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 1157 | } |
| 1158 | |
Johannes Stezenbach | fdc53a6 | 2005-05-16 21:54:39 -0700 | [diff] [blame] | 1159 | budget_av->budget.dvb_adapter.priv = budget_av; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | frontend_init(budget_av); |
Andrew de Quincey | c5e768a | 2006-06-29 13:16:11 -0300 | [diff] [blame] | 1161 | ciintf_init(budget_av); |
Oliver Endriss | 32e4c3a | 2006-07-18 22:55:23 -0300 | [diff] [blame] | 1162 | |
| 1163 | ttpci_budget_init_hooks(&budget_av->budget); |
| 1164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | #define KNC1_INPUTS 2 |
| 1169 | static struct v4l2_input knc1_inputs[KNC1_INPUTS] = { |
| 1170 | {0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0}, |
| 1171 | {1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0}, |
| 1172 | }; |
| 1173 | |
| 1174 | static struct saa7146_extension_ioctls ioctls[] = { |
| 1175 | {VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE}, |
| 1176 | {VIDIOC_G_INPUT, SAA7146_EXCLUSIVE}, |
| 1177 | {VIDIOC_S_INPUT, SAA7146_EXCLUSIVE}, |
| 1178 | {0, 0} |
| 1179 | }; |
| 1180 | |
| 1181 | static int av_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg) |
| 1182 | { |
| 1183 | struct saa7146_dev *dev = fh->dev; |
| 1184 | struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; |
| 1185 | |
| 1186 | switch (cmd) { |
| 1187 | case VIDIOC_ENUMINPUT:{ |
| 1188 | struct v4l2_input *i = arg; |
| 1189 | |
| 1190 | dprintk(1, "VIDIOC_ENUMINPUT %d.\n", i->index); |
| 1191 | if (i->index < 0 || i->index >= KNC1_INPUTS) { |
| 1192 | return -EINVAL; |
| 1193 | } |
| 1194 | memcpy(i, &knc1_inputs[i->index], sizeof(struct v4l2_input)); |
| 1195 | return 0; |
| 1196 | } |
| 1197 | case VIDIOC_G_INPUT:{ |
| 1198 | int *input = (int *) arg; |
| 1199 | |
| 1200 | *input = budget_av->cur_input; |
| 1201 | |
| 1202 | dprintk(1, "VIDIOC_G_INPUT %d.\n", *input); |
| 1203 | return 0; |
| 1204 | } |
| 1205 | case VIDIOC_S_INPUT:{ |
| 1206 | int input = *(int *) arg; |
| 1207 | dprintk(1, "VIDIOC_S_INPUT %d.\n", input); |
| 1208 | return saa7113_setinput(budget_av, input); |
| 1209 | } |
| 1210 | default: |
| 1211 | return -ENOIOCTLCMD; |
| 1212 | } |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | static struct saa7146_standard standard[] = { |
| 1217 | {.name = "PAL",.id = V4L2_STD_PAL, |
| 1218 | .v_offset = 0x17,.v_field = 288, |
| 1219 | .h_offset = 0x14,.h_pixels = 680, |
| 1220 | .v_max_out = 576,.h_max_out = 768 }, |
| 1221 | |
| 1222 | {.name = "NTSC",.id = V4L2_STD_NTSC, |
| 1223 | .v_offset = 0x16,.v_field = 240, |
| 1224 | .h_offset = 0x06,.h_pixels = 708, |
| 1225 | .v_max_out = 480,.h_max_out = 640, }, |
| 1226 | }; |
| 1227 | |
| 1228 | static struct saa7146_ext_vv vv_data = { |
| 1229 | .inputs = 2, |
| 1230 | .capabilities = 0, // perhaps later: V4L2_CAP_VBI_CAPTURE, but that need tweaking with the saa7113 |
| 1231 | .flags = 0, |
| 1232 | .stds = &standard[0], |
| 1233 | .num_stds = sizeof(standard) / sizeof(struct saa7146_standard), |
| 1234 | .ioctls = &ioctls[0], |
| 1235 | .ioctl = av_ioctl, |
| 1236 | }; |
| 1237 | |
| 1238 | static struct saa7146_extension budget_extension; |
| 1239 | |
| 1240 | MAKE_BUDGET_INFO(knc1s, "KNC1 DVB-S", BUDGET_KNC1S); |
| 1241 | MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C); |
| 1242 | MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T); |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 1243 | MAKE_BUDGET_INFO(kncxs, "KNC TV STAR DVB-S", BUDGET_TVSTAR); |
Thilo Berger | 36f4f33 | 2006-02-27 00:09:08 -0300 | [diff] [blame] | 1244 | MAKE_BUDGET_INFO(satewpls, "Satelco EasyWatch DVB-S light", BUDGET_TVSTAR); |
Lothar Englisch | 60110ce | 2006-06-06 16:13:46 -0300 | [diff] [blame] | 1245 | MAKE_BUDGET_INFO(satewpls1, "Satelco EasyWatch DVB-S light", BUDGET_KNC1S); |
Thomas Hamm | c01d1e4 | 2006-11-17 07:12:58 -0300 | [diff] [blame] | 1246 | MAKE_BUDGET_INFO(satewplc, "Satelco EasyWatch DVB-C", BUDGET_KNC1CP); |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 1247 | MAKE_BUDGET_INFO(satewcmk3, "Satelco EasyWatch DVB-C MK3", BUDGET_KNC1C_MK3); |
Johannes Stezenbach | 2d4f2c2 | 2005-05-16 21:54:23 -0700 | [diff] [blame] | 1248 | MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP); |
| 1249 | MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP); |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 1250 | MAKE_BUDGET_INFO(knc1cmk3, "KNC1 DVB-C MK3", BUDGET_KNC1C_MK3); |
| 1251 | MAKE_BUDGET_INFO(knc1cpmk3, "KNC1 DVB-C Plus MK3", BUDGET_KNC1CP_MK3); |
Johannes Stezenbach | 2d4f2c2 | 2005-05-16 21:54:23 -0700 | [diff] [blame] | 1252 | MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S); |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 1254 | MAKE_BUDGET_INFO(cin1200sn, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C); |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 1256 | MAKE_BUDGET_INFO(cin1200cmk3, "Terratec Cinergy 1200 DVB-C MK3", BUDGET_CIN1200C_MK3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T); |
| 1258 | |
| 1259 | static struct pci_device_id pci_tbl[] = { |
| 1260 | MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x4f56), |
Johannes Stezenbach | 2d4f2c2 | 2005-05-16 21:54:23 -0700 | [diff] [blame] | 1261 | MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x0010), |
Andrew de Quincey | effa791 | 2006-01-09 15:25:09 -0200 | [diff] [blame] | 1262 | MAKE_EXTENSION_PCI(knc1s, 0x1894, 0x0010), |
Johannes Stezenbach | 2d4f2c2 | 2005-05-16 21:54:23 -0700 | [diff] [blame] | 1263 | MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011), |
Christoph Pfister | 4e318be | 2006-08-12 09:13:35 -0300 | [diff] [blame] | 1264 | MAKE_EXTENSION_PCI(knc1sp, 0x1894, 0x0011), |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 1265 | MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0014), |
| 1266 | MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016), |
Thilo Berger | 36f4f33 | 2006-02-27 00:09:08 -0300 | [diff] [blame] | 1267 | MAKE_EXTENSION_PCI(satewpls, 0x1894, 0x001e), |
Lothar Englisch | 60110ce | 2006-06-06 16:13:46 -0300 | [diff] [blame] | 1268 | MAKE_EXTENSION_PCI(satewpls1, 0x1894, 0x001a), |
Thomas Hamm | c01d1e4 | 2006-11-17 07:12:58 -0300 | [diff] [blame] | 1269 | MAKE_EXTENSION_PCI(satewplc, 0x1894, 0x002a), |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 1270 | MAKE_EXTENSION_PCI(satewcmk3, 0x1894, 0x002c), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020), |
Johannes Stezenbach | 2d4f2c2 | 2005-05-16 21:54:23 -0700 | [diff] [blame] | 1272 | MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021), |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 1273 | MAKE_EXTENSION_PCI(knc1cmk3, 0x1894, 0x0022), |
| 1274 | MAKE_EXTENSION_PCI(knc1cpmk3, 0x1894, 0x0023), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030), |
Johannes Stezenbach | 2d4f2c2 | 2005-05-16 21:54:23 -0700 | [diff] [blame] | 1276 | MAKE_EXTENSION_PCI(knc1tp, 0x1894, 0x0031), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | MAKE_EXTENSION_PCI(cin1200s, 0x153b, 0x1154), |
Regis Prevot | f8bf134 | 2006-01-11 23:31:53 -0200 | [diff] [blame] | 1278 | MAKE_EXTENSION_PCI(cin1200sn, 0x153b, 0x1155), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | MAKE_EXTENSION_PCI(cin1200c, 0x153b, 0x1156), |
Hartmut Birr | aa323ac | 2007-04-21 19:37:17 -0300 | [diff] [blame] | 1280 | MAKE_EXTENSION_PCI(cin1200cmk3, 0x153b, 0x1176), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | MAKE_EXTENSION_PCI(cin1200t, 0x153b, 0x1157), |
| 1282 | { |
| 1283 | .vendor = 0, |
| 1284 | } |
| 1285 | }; |
| 1286 | |
| 1287 | MODULE_DEVICE_TABLE(pci, pci_tbl); |
| 1288 | |
| 1289 | static struct saa7146_extension budget_extension = { |
Julian Scheel | 27b05fd | 2005-07-12 13:58:39 -0700 | [diff] [blame] | 1290 | .name = "budget_av", |
Oliver Endriss | 00c4cc6 | 2006-11-01 13:09:51 -0300 | [diff] [blame] | 1291 | .flags = SAA7146_USE_I2C_IRQ, |
Oliver Endriss | 69459f3d | 2005-12-01 00:51:48 -0800 | [diff] [blame] | 1292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | .pci_tbl = pci_tbl, |
| 1294 | |
| 1295 | .module = THIS_MODULE, |
| 1296 | .attach = budget_av_attach, |
| 1297 | .detach = budget_av_detach, |
| 1298 | |
| 1299 | .irq_mask = MASK_10, |
| 1300 | .irq_func = budget_av_irq, |
| 1301 | }; |
| 1302 | |
| 1303 | static int __init budget_av_init(void) |
| 1304 | { |
| 1305 | return saa7146_register_extension(&budget_extension); |
| 1306 | } |
| 1307 | |
| 1308 | static void __exit budget_av_exit(void) |
| 1309 | { |
| 1310 | saa7146_unregister_extension(&budget_extension); |
| 1311 | } |
| 1312 | |
| 1313 | module_init(budget_av_init); |
| 1314 | module_exit(budget_av_exit); |
| 1315 | |
| 1316 | MODULE_LICENSE("GPL"); |
| 1317 | MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others"); |
| 1318 | MODULE_DESCRIPTION("driver for the SAA7146 based so-called " |
| 1319 | "budget PCI DVB w/ analog input and CI-module (e.g. the KNC cards)"); |