Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX23885 PCIe bridge |
| 3 | * |
| 4 | * Copyright (c) 2006 Steven Toth <stoth@hauppauge.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/i2c.h> |
| 24 | #include <linux/i2c-algo-bit.h> |
| 25 | #include <linux/kdev_t.h> |
| 26 | |
| 27 | #include <media/v4l2-common.h> |
| 28 | #include <media/tuner.h> |
| 29 | #include <media/tveeprom.h> |
| 30 | #include <media/video-buf.h> |
Michael Krufky | 03121f05 | 2007-03-11 20:57:52 -0300 | [diff] [blame] | 31 | #if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 32 | #include <media/video-buf-dvb.h> |
Michael Krufky | 03121f05 | 2007-03-11 20:57:52 -0300 | [diff] [blame] | 33 | #endif |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 34 | |
| 35 | #include "btcx-risc.h" |
| 36 | #include "cx23885-reg.h" |
| 37 | |
| 38 | #include <linux/version.h> |
| 39 | #include <linux/mutex.h> |
| 40 | |
Steven Toth | 047646b | 2007-03-20 15:33:53 -0300 | [diff] [blame] | 41 | #define CX23885_VERSION_CODE KERNEL_VERSION(0,0,1) |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 42 | |
| 43 | #define UNSET (-1U) |
| 44 | |
| 45 | #define CX23885_MAXBOARDS 8 |
| 46 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 47 | /* Max number of inputs by card */ |
| 48 | #define MAX_CX23885_INPUT 8 |
| 49 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 50 | #define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */ |
| 51 | |
| 52 | #define CX23885_BOARD_NOAUTO UNSET |
| 53 | #define CX23885_BOARD_UNKNOWN 0 |
| 54 | #define CX23885_BOARD_HAUPPAUGE_HVR1800lp 1 |
| 55 | #define CX23885_BOARD_HAUPPAUGE_HVR1800 2 |
Steven Toth | a77743b | 2007-08-22 21:01:20 -0300 | [diff] [blame] | 56 | #define CX23885_BOARD_HAUPPAUGE_HVR1250 3 |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 57 | |
| 58 | enum cx23885_itype { |
| 59 | CX23885_VMUX_COMPOSITE1 = 1, |
| 60 | CX23885_VMUX_COMPOSITE2, |
| 61 | CX23885_VMUX_COMPOSITE3, |
| 62 | CX23885_VMUX_COMPOSITE4, |
| 63 | CX23885_VMUX_SVIDEO, |
| 64 | CX23885_VMUX_TELEVISION, |
| 65 | CX23885_VMUX_CABLE, |
| 66 | CX23885_VMUX_DVB, |
| 67 | CX23885_VMUX_DEBUG, |
| 68 | CX23885_RADIO, |
| 69 | }; |
| 70 | |
Steven Toth | 579f116 | 2007-09-08 15:07:02 -0300 | [diff] [blame^] | 71 | enum cx23885_src_sel_type { |
| 72 | CX23885_SRC_SEL_EXT_656_VIDEO = 0, |
| 73 | CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO |
| 74 | }; |
| 75 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 76 | /* buffer for one video frame */ |
| 77 | struct cx23885_buffer { |
| 78 | /* common v4l buffer stuff -- must be first */ |
| 79 | struct videobuf_buffer vb; |
| 80 | |
| 81 | /* cx23885 specific */ |
| 82 | unsigned int bpl; |
| 83 | struct btcx_riscmem risc; |
| 84 | struct cx23885_fmt *fmt; |
| 85 | u32 count; |
| 86 | }; |
| 87 | |
| 88 | struct cx23885_input { |
| 89 | enum cx23885_itype type; |
| 90 | unsigned int vmux; |
| 91 | u32 gpio0, gpio1, gpio2, gpio3; |
| 92 | }; |
| 93 | |
Steven Toth | 661c7e4 | 2007-09-06 16:07:49 -0300 | [diff] [blame] | 94 | typedef enum { |
| 95 | CX23885_MPEG_UNDEFINED = 0, |
| 96 | CX23885_MPEG_DVB |
| 97 | } port_t; |
| 98 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 99 | struct cx23885_board { |
| 100 | char *name; |
Steven Toth | 661c7e4 | 2007-09-06 16:07:49 -0300 | [diff] [blame] | 101 | port_t portb, portc; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 102 | struct cx23885_input input[MAX_CX23885_INPUT]; |
| 103 | }; |
| 104 | |
| 105 | struct cx23885_subid { |
| 106 | u16 subvendor; |
| 107 | u16 subdevice; |
| 108 | u32 card; |
| 109 | }; |
| 110 | |
| 111 | struct cx23885_i2c { |
| 112 | struct cx23885_dev *dev; |
| 113 | |
| 114 | int nr; |
| 115 | |
| 116 | /* i2c i/o */ |
| 117 | struct i2c_adapter i2c_adap; |
| 118 | struct i2c_algo_bit_data i2c_algo; |
| 119 | struct i2c_client i2c_client; |
| 120 | u32 i2c_rc; |
| 121 | |
| 122 | /* 885 registers used for raw addess */ |
| 123 | u32 i2c_period; |
| 124 | u32 reg_ctrl; |
| 125 | u32 reg_stat; |
| 126 | u32 reg_addr; |
| 127 | u32 reg_rdata; |
| 128 | u32 reg_wdata; |
| 129 | }; |
| 130 | |
| 131 | struct cx23885_dmaqueue { |
| 132 | struct list_head active; |
| 133 | struct list_head queued; |
| 134 | struct timer_list timeout; |
| 135 | struct btcx_riscmem stopper; |
| 136 | u32 count; |
| 137 | }; |
| 138 | |
| 139 | struct cx23885_tsport { |
| 140 | struct cx23885_dev *dev; |
| 141 | |
| 142 | int nr; |
| 143 | int sram_chno; |
| 144 | |
| 145 | struct videobuf_dvb dvb; |
| 146 | |
| 147 | /* dma queues */ |
| 148 | struct cx23885_dmaqueue mpegq; |
| 149 | u32 ts_packet_size; |
| 150 | u32 ts_packet_count; |
| 151 | |
| 152 | int width; |
| 153 | int height; |
| 154 | |
| 155 | spinlock_t slock; |
| 156 | |
| 157 | /* registers */ |
| 158 | u32 reg_gpcnt; |
| 159 | u32 reg_gpcnt_ctl; |
| 160 | u32 reg_dma_ctl; |
| 161 | u32 reg_lngth; |
| 162 | u32 reg_hw_sop_ctrl; |
| 163 | u32 reg_gen_ctrl; |
| 164 | u32 reg_bd_pkt_status; |
| 165 | u32 reg_sop_status; |
| 166 | u32 reg_fifo_ovfl_stat; |
| 167 | u32 reg_vld_misc; |
| 168 | u32 reg_ts_clk_en; |
| 169 | u32 reg_ts_int_msk; |
Steven Toth | 579f116 | 2007-09-08 15:07:02 -0300 | [diff] [blame^] | 170 | u32 reg_src_sel; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 171 | |
| 172 | /* Default register vals */ |
| 173 | int pci_irqmask; |
| 174 | u32 dma_ctl_val; |
| 175 | u32 ts_int_msk_val; |
| 176 | u32 gen_ctrl_val; |
| 177 | u32 ts_clk_en_val; |
Steven Toth | 579f116 | 2007-09-08 15:07:02 -0300 | [diff] [blame^] | 178 | u32 src_sel_val; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | struct cx23885_dev { |
| 182 | struct list_head devlist; |
| 183 | atomic_t refcount; |
| 184 | |
| 185 | /* pci stuff */ |
| 186 | struct pci_dev *pci; |
| 187 | unsigned char pci_rev, pci_lat; |
| 188 | int pci_bus, pci_slot; |
| 189 | u32 __iomem *lmmio; |
| 190 | u8 __iomem *bmmio; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 191 | int pci_irqmask; |
| 192 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 193 | /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */ |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 194 | struct cx23885_i2c i2c_bus[3]; |
| 195 | |
| 196 | int nr; |
| 197 | struct mutex lock; |
| 198 | |
| 199 | /* board details */ |
| 200 | unsigned int board; |
| 201 | char name[32]; |
| 202 | |
| 203 | struct cx23885_tsport ts2; |
| 204 | |
| 205 | /* sram configuration */ |
| 206 | struct sram_channel *sram_channels; |
Steven Toth | e133be0 | 2007-03-19 19:22:41 -0300 | [diff] [blame] | 207 | |
| 208 | enum { |
| 209 | CX23885_BRIDGE_UNDEFINED = 0, |
| 210 | CX23885_BRIDGE_885 = 885, |
| 211 | CX23885_BRIDGE_887 = 887, |
| 212 | } bridge; |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | #define SRAM_CH01 0 /* Video A */ |
| 216 | #define SRAM_CH02 1 /* VBI A */ |
| 217 | #define SRAM_CH03 2 /* Video B */ |
| 218 | #define SRAM_CH04 3 /* Transport via B */ |
| 219 | #define SRAM_CH05 4 /* VBI B */ |
| 220 | #define SRAM_CH06 5 /* Video C */ |
| 221 | #define SRAM_CH07 6 /* Transport via C */ |
| 222 | #define SRAM_CH08 7 /* Audio Internal A */ |
| 223 | #define SRAM_CH09 8 /* Audio Internal B */ |
| 224 | #define SRAM_CH10 9 /* Audio External */ |
| 225 | #define SRAM_CH11 10 /* COMB_3D_N */ |
| 226 | #define SRAM_CH12 11 /* Comb 3D N1 */ |
| 227 | #define SRAM_CH13 12 /* Comb 3D N2 */ |
| 228 | #define SRAM_CH14 13 /* MOE Vid */ |
| 229 | #define SRAM_CH15 14 /* MOE RSLT */ |
| 230 | |
| 231 | struct sram_channel { |
| 232 | char *name; |
| 233 | u32 cmds_start; |
| 234 | u32 ctrl_start; |
| 235 | u32 cdt; |
| 236 | u32 fifo_start;; |
| 237 | u32 fifo_size; |
| 238 | u32 ptr1_reg; |
| 239 | u32 ptr2_reg; |
| 240 | u32 cnt1_reg; |
| 241 | u32 cnt2_reg; |
| 242 | u32 jumponly; |
| 243 | }; |
| 244 | |
| 245 | /* ----------------------------------------------------------- */ |
| 246 | |
| 247 | #define cx_read(reg) readl(dev->lmmio + ((reg)>>2)) |
| 248 | #define cx_write(reg,value) writel((value), dev->lmmio + ((reg)>>2)) |
| 249 | |
| 250 | #define cx_andor(reg,mask,value) \ |
| 251 | writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\ |
| 252 | ((value) & (mask)), dev->lmmio+((reg)>>2)) |
| 253 | |
| 254 | #define cx_set(reg,bit) cx_andor((reg),(bit),(bit)) |
| 255 | #define cx_clear(reg,bit) cx_andor((reg),(bit),0) |
| 256 | |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 257 | extern int cx23885_sram_channel_setup(struct cx23885_dev *dev, |
| 258 | struct sram_channel *ch, |
| 259 | unsigned int bpl, u32 risc); |
| 260 | |
| 261 | /* ----------------------------------------------------------- */ |
| 262 | /* cx23885-cards.c */ |
| 263 | |
| 264 | extern struct cx23885_board cx23885_boards[]; |
| 265 | extern const unsigned int cx23885_bcount; |
| 266 | |
| 267 | extern struct cx23885_subid cx23885_subids[]; |
| 268 | extern const unsigned int cx23885_idcount; |
| 269 | |
| 270 | extern void cx23885_card_list(struct cx23885_dev *dev); |
| 271 | extern void cx23885_card_setup(struct cx23885_dev *dev); |
| 272 | extern void cx23885_card_setup_pre_i2c(struct cx23885_dev *dev); |
| 273 | |
| 274 | extern int cx23885_dvb_register(struct cx23885_tsport *port); |
| 275 | extern int cx23885_dvb_unregister(struct cx23885_tsport *port); |
| 276 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 277 | extern int cx23885_buf_prepare(struct videobuf_queue *q, |
| 278 | struct cx23885_tsport *port, |
| 279 | struct cx23885_buffer *buf, |
| 280 | enum v4l2_field field); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 281 | |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 282 | extern void cx23885_buf_queue(struct cx23885_tsport *port, |
| 283 | struct cx23885_buffer *buf); |
| 284 | extern void cx23885_free_buffer(struct videobuf_queue *q, |
| 285 | struct cx23885_buffer *buf); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 286 | |
| 287 | /* ----------------------------------------------------------- */ |
| 288 | /* cx23885-i2c.c */ |
| 289 | extern int cx23885_i2c_register(struct cx23885_i2c *bus); |
| 290 | extern int cx23885_i2c_unregister(struct cx23885_i2c *bus); |
Michael Krufky | 44a6481 | 2007-03-20 23:00:18 -0300 | [diff] [blame] | 291 | extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd, |
| 292 | void *arg); |
Steven Toth | d19770e | 2007-03-11 20:44:05 -0300 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * Local variables: |
| 296 | * c-basic-offset: 8 |
| 297 | * End: |
| 298 | * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off |
| 299 | */ |