Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Driver for the Conexant CX25821 PCIe bridge |
| 4 | * |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 5 | * Copyright (C) 2009 Conexant Systems Inc. |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 6 | * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> |
| 7 | * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 8 | */ |
| 9 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 10 | #ifndef CX25821_H_ |
| 11 | #define CX25821_H_ |
| 12 | |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/i2c.h> |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/sched.h> |
| 18 | #include <linux/kdev_t.h> |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 19 | |
| 20 | #include <media/v4l2-common.h> |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 21 | #include <media/v4l2-device.h> |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 22 | #include <media/v4l2-ctrls.h> |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 23 | #include <media/videobuf2-v4l2.h> |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 24 | #include <media/videobuf2-dma-sg.h> |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 25 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 26 | #include "cx25821-reg.h" |
| 27 | #include "cx25821-medusa-reg.h" |
| 28 | #include "cx25821-sram.h" |
| 29 | #include "cx25821-audio.h" |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 30 | |
| 31 | #include <linux/version.h> |
| 32 | #include <linux/mutex.h> |
| 33 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 34 | #define UNSET (-1U) |
| 35 | #define NO_SYNC_LINE (-1U) |
| 36 | |
| 37 | #define CX25821_MAXBOARDS 2 |
| 38 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 39 | #define LINE_SIZE_D1 1440 |
| 40 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 41 | /* Number of decoders and encoders */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 42 | #define MAX_DECODERS 8 |
| 43 | #define MAX_ENCODERS 2 |
| 44 | #define QUAD_DECODERS 4 |
| 45 | #define MAX_CAMERAS 16 |
| 46 | |
| 47 | /* Max number of inputs by card */ |
Leonid V. Fedorenchik | c7855ee | 2011-10-22 01:43:56 -0300 | [diff] [blame] | 48 | #define MAX_CX25821_INPUT 8 |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 49 | #define RESOURCE_VIDEO0 1 |
| 50 | #define RESOURCE_VIDEO1 2 |
| 51 | #define RESOURCE_VIDEO2 4 |
| 52 | #define RESOURCE_VIDEO3 8 |
| 53 | #define RESOURCE_VIDEO4 16 |
| 54 | #define RESOURCE_VIDEO5 32 |
| 55 | #define RESOURCE_VIDEO6 64 |
| 56 | #define RESOURCE_VIDEO7 128 |
| 57 | #define RESOURCE_VIDEO8 256 |
| 58 | #define RESOURCE_VIDEO9 512 |
| 59 | #define RESOURCE_VIDEO10 1024 |
| 60 | #define RESOURCE_VIDEO11 2048 |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 61 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 62 | #define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 63 | |
Leonid V. Fedorenchik | c7855ee | 2011-10-22 01:43:56 -0300 | [diff] [blame] | 64 | #define UNKNOWN_BOARD 0 |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 65 | #define CX25821_BOARD 1 |
| 66 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 67 | /* Currently supported by the driver */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 68 | #define CX25821_NORMS (\ |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 69 | V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR | \ |
| 70 | V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \ |
| 71 | V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_H | \ |
| 72 | V4L2_STD_PAL_Nc) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 73 | |
| 74 | #define CX25821_BOARD_CONEXANT_ATHENA10 1 |
| 75 | #define MAX_VID_CHANNEL_NUM 12 |
Hans Verkuil | b6f21dc | 2014-12-12 10:28:00 -0300 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Maximum capture-only channels. This can go away once video/audio output |
| 79 | * is fully supported in this driver. |
| 80 | */ |
| 81 | #define MAX_VID_CAP_CHANNEL_NUM 10 |
| 82 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 83 | #define VID_CHANNEL_NUM 8 |
| 84 | |
| 85 | struct cx25821_fmt { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 86 | char *name; |
| 87 | u32 fourcc; /* v4l2 format id */ |
| 88 | int depth; |
| 89 | int flags; |
| 90 | u32 cxformat; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 91 | }; |
| 92 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 93 | struct cx25821_tvnorm { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 94 | char *name; |
| 95 | v4l2_std_id id; |
| 96 | u32 cxiformat; |
| 97 | u32 cxoformat; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 98 | }; |
| 99 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 100 | enum cx25821_src_sel_type { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 101 | CX25821_SRC_SEL_EXT_656_VIDEO = 0, |
| 102 | CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 103 | }; |
| 104 | |
Hans Verkuil | 5ede94c | 2014-12-12 10:27:54 -0300 | [diff] [blame] | 105 | struct cx25821_riscmem { |
| 106 | unsigned int size; |
| 107 | __le32 *cpu; |
| 108 | __le32 *jmp; |
| 109 | dma_addr_t dma; |
| 110 | }; |
| 111 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 112 | /* buffer for one video frame */ |
| 113 | struct cx25821_buffer { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 114 | /* common v4l buffer stuff -- must be first */ |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 115 | struct vb2_v4l2_buffer vb; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 116 | struct list_head queue; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 117 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 118 | /* cx25821 specific */ |
| 119 | unsigned int bpl; |
Hans Verkuil | 5ede94c | 2014-12-12 10:27:54 -0300 | [diff] [blame] | 120 | struct cx25821_riscmem risc; |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 121 | const struct cx25821_fmt *fmt; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 122 | }; |
| 123 | |
Leonid V. Fedorenchik | 7ae70c8 | 2011-09-02 11:55:29 +0800 | [diff] [blame] | 124 | enum port { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 125 | CX25821_UNDEFINED = 0, |
| 126 | CX25821_RAW, |
| 127 | CX25821_264 |
Leonid V. Fedorenchik | 7ae70c8 | 2011-09-02 11:55:29 +0800 | [diff] [blame] | 128 | }; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 129 | |
| 130 | struct cx25821_board { |
Ezequiel GarcÃa | c854d88 | 2012-07-18 13:41:11 -0300 | [diff] [blame] | 131 | const char *name; |
Leonid V. Fedorenchik | 7ae70c8 | 2011-09-02 11:55:29 +0800 | [diff] [blame] | 132 | enum port porta; |
| 133 | enum port portb; |
| 134 | enum port portc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 135 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 136 | u32 clk_freq; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 137 | }; |
| 138 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 139 | struct cx25821_i2c { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 140 | struct cx25821_dev *dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 141 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 142 | int nr; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 143 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 144 | /* i2c i/o */ |
| 145 | struct i2c_adapter i2c_adap; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 146 | struct i2c_client i2c_client; |
| 147 | u32 i2c_rc; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 148 | |
Mauro Carvalho Chehab | 1679055 | 2019-02-18 14:28:59 -0500 | [diff] [blame] | 149 | /* cx25821 registers used for raw address */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 150 | u32 i2c_period; |
| 151 | u32 reg_ctrl; |
| 152 | u32 reg_stat; |
| 153 | u32 reg_addr; |
| 154 | u32 reg_rdata; |
| 155 | u32 reg_wdata; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | struct cx25821_dmaqueue { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 159 | struct list_head active; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 160 | u32 count; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 161 | }; |
| 162 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 163 | struct cx25821_dev; |
| 164 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 165 | struct cx25821_channel; |
| 166 | |
| 167 | struct cx25821_video_out_data { |
| 168 | struct cx25821_channel *chan; |
| 169 | int _line_size; |
| 170 | int _prog_cnt; |
| 171 | int _pixel_format; |
| 172 | int _is_first_frame; |
| 173 | int _is_running; |
| 174 | int _file_status; |
| 175 | int _lines_count; |
| 176 | int _frame_count; |
| 177 | unsigned int _risc_size; |
| 178 | |
| 179 | __le32 *_dma_virt_start_addr; |
| 180 | __le32 *_dma_virt_addr; |
| 181 | dma_addr_t _dma_phys_addr; |
| 182 | dma_addr_t _dma_phys_start_addr; |
| 183 | |
| 184 | unsigned int _data_buf_size; |
| 185 | __le32 *_data_buf_virt_addr; |
| 186 | dma_addr_t _data_buf_phys_addr; |
| 187 | |
| 188 | u32 upstream_riscbuf_size; |
| 189 | u32 upstream_databuf_size; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 190 | int is_60hz; |
| 191 | int _frame_index; |
Hans Verkuil | ea3f7ac | 2013-04-14 12:02:19 -0300 | [diff] [blame] | 192 | int cur_frame_index; |
| 193 | int curpos; |
| 194 | wait_queue_head_t waitq; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 195 | }; |
| 196 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 197 | struct cx25821_channel { |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 198 | unsigned id; |
| 199 | struct cx25821_dev *dev; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 200 | |
Hans Verkuil | f8d7ee7 | 2013-04-13 08:38:14 -0300 | [diff] [blame] | 201 | struct v4l2_ctrl_handler hdl; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 202 | |
Hans Verkuil | 467870c | 2013-04-13 08:18:00 -0300 | [diff] [blame] | 203 | struct video_device vdev; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 204 | struct cx25821_dmaqueue dma_vidq; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 205 | struct vb2_queue vidq; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 206 | |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 207 | const struct sram_channel *sram_channels; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 208 | |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 209 | const struct cx25821_fmt *fmt; |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 210 | unsigned field; |
Hans Verkuil | 2efe2cc | 2013-04-13 10:00:52 -0300 | [diff] [blame] | 211 | unsigned int width, height; |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 212 | int pixel_formats; |
| 213 | int use_cif_resolution; |
| 214 | int cif_width; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 215 | |
| 216 | /* video output data for the video output channel */ |
| 217 | struct cx25821_video_out_data *out; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 218 | }; |
| 219 | |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 220 | struct snd_card; |
| 221 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 222 | struct cx25821_dev { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 223 | struct v4l2_device v4l2_dev; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 224 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 225 | /* pci stuff */ |
| 226 | struct pci_dev *pci; |
| 227 | unsigned char pci_rev, pci_lat; |
| 228 | int pci_bus, pci_slot; |
| 229 | u32 base_io_addr; |
| 230 | u32 __iomem *lmmio; |
| 231 | u8 __iomem *bmmio; |
| 232 | int pci_irqmask; |
| 233 | int hwrevision; |
Hans Verkuil | a8f35ce | 2013-04-13 07:07:40 -0300 | [diff] [blame] | 234 | /* used by cx25821-alsa */ |
| 235 | struct snd_card *card; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 236 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 237 | u32 clk_freq; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 238 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 239 | /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */ |
| 240 | struct cx25821_i2c i2c_bus[3]; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 241 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 242 | int nr; |
| 243 | struct mutex lock; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 244 | |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 245 | struct cx25821_channel channels[MAX_VID_CHANNEL_NUM]; |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 246 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 247 | /* board details */ |
| 248 | unsigned int board; |
| 249 | char name[32]; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 250 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 251 | /* Analog video */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 252 | unsigned int input; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 253 | v4l2_std_id tvnorm; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 254 | unsigned short _max_num_decoders; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 255 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 256 | /* Analog Audio Upstream */ |
| 257 | int _audio_is_running; |
| 258 | int _audiopixel_format; |
| 259 | int _is_first_audio_frame; |
| 260 | int _audiofile_status; |
| 261 | int _audio_lines_count; |
| 262 | int _audioframe_count; |
Leonid V. Fedorenchik | 6100c57 | 2011-09-02 11:55:30 +0800 | [diff] [blame] | 263 | int _audio_upstream_channel; |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 264 | int _last_index_irq; /* The last interrupt index processed. */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 265 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 266 | __le32 *_risc_audio_jmp_addr; |
| 267 | __le32 *_risc_virt_start_addr; |
| 268 | __le32 *_risc_virt_addr; |
| 269 | dma_addr_t _risc_phys_addr; |
| 270 | dma_addr_t _risc_phys_start_addr; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 271 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 272 | unsigned int _audiorisc_size; |
| 273 | unsigned int _audiodata_buf_size; |
| 274 | __le32 *_audiodata_buf_virt_addr; |
| 275 | dma_addr_t _audiodata_buf_phys_addr; |
| 276 | char *_audiofilename; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 277 | u32 audio_upstream_riscbuf_size; |
| 278 | u32 audio_upstream_databuf_size; |
| 279 | int _audioframe_index; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 280 | struct work_struct _audio_work_entry; |
| 281 | char *input_audiofilename; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 282 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 283 | /* V4l */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 284 | spinlock_t slock; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 285 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 286 | /* Video Upstream */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame] | 287 | struct cx25821_video_out_data vid_out_data[2]; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 288 | }; |
| 289 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 290 | static inline struct cx25821_dev *get_cx25821(struct v4l2_device *v4l2_dev) |
| 291 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 292 | return container_of(v4l2_dev, struct cx25821_dev, v4l2_dev); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 293 | } |
| 294 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 295 | extern struct cx25821_board cx25821_boards[]; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 296 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 297 | #define SRAM_CH00 0 /* Video A */ |
| 298 | #define SRAM_CH01 1 /* Video B */ |
| 299 | #define SRAM_CH02 2 /* Video C */ |
| 300 | #define SRAM_CH03 3 /* Video D */ |
| 301 | #define SRAM_CH04 4 /* Video E */ |
| 302 | #define SRAM_CH05 5 /* Video F */ |
| 303 | #define SRAM_CH06 6 /* Video G */ |
| 304 | #define SRAM_CH07 7 /* Video H */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 305 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 306 | #define SRAM_CH08 8 /* Audio A */ |
| 307 | #define SRAM_CH09 9 /* Video Upstream I */ |
| 308 | #define SRAM_CH10 10 /* Video Upstream J */ |
| 309 | #define SRAM_CH11 11 /* Audio Upstream AUD_CHANNEL_B */ |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 310 | |
| 311 | #define VID_UPSTREAM_SRAM_CHANNEL_I SRAM_CH09 |
| 312 | #define VID_UPSTREAM_SRAM_CHANNEL_J SRAM_CH10 |
| 313 | #define AUDIO_UPSTREAM_SRAM_CHANNEL_B SRAM_CH11 |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 314 | |
| 315 | struct sram_channel { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 316 | char *name; |
| 317 | u32 i; |
| 318 | u32 cmds_start; |
| 319 | u32 ctrl_start; |
| 320 | u32 cdt; |
| 321 | u32 fifo_start; |
| 322 | u32 fifo_size; |
| 323 | u32 ptr1_reg; |
| 324 | u32 ptr2_reg; |
| 325 | u32 cnt1_reg; |
| 326 | u32 cnt2_reg; |
| 327 | u32 int_msk; |
| 328 | u32 int_stat; |
| 329 | u32 int_mstat; |
| 330 | u32 dma_ctl; |
| 331 | u32 gpcnt_ctl; |
| 332 | u32 gpcnt; |
| 333 | u32 aud_length; |
| 334 | u32 aud_cfg; |
| 335 | u32 fld_aud_fifo_en; |
| 336 | u32 fld_aud_risc_en; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 337 | |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 338 | /* For Upstream Video */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 339 | u32 vid_fmt_ctl; |
| 340 | u32 vid_active_ctl1; |
| 341 | u32 vid_active_ctl2; |
| 342 | u32 vid_cdt_size; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 343 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 344 | u32 vip_ctl; |
| 345 | u32 pix_frmt; |
| 346 | u32 jumponly; |
| 347 | u32 irq_bit; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 348 | }; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 349 | |
| 350 | extern const struct sram_channel cx25821_sram_channels[]; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 351 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 352 | #define cx_read(reg) readl(dev->lmmio + ((reg)>>2)) |
| 353 | #define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2)) |
| 354 | |
| 355 | #define cx_andor(reg, mask, value) \ |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 356 | writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\ |
| 357 | ((value) & (mask)), dev->lmmio+((reg)>>2)) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 358 | |
| 359 | #define cx_set(reg, bit) cx_andor((reg), (bit), (bit)) |
| 360 | #define cx_clear(reg, bit) cx_andor((reg), (bit), 0) |
| 361 | |
| 362 | #define Set_GPIO_Bit(Bit) (1 << Bit) |
| 363 | #define Clear_GPIO_Bit(Bit) (~(1 << Bit)) |
| 364 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 365 | #define CX25821_ERR(fmt, args...) \ |
| 366 | pr_err("(%d): " fmt, dev->board, ##args) |
| 367 | #define CX25821_WARN(fmt, args...) \ |
| 368 | pr_warn("(%d): " fmt, dev->board, ##args) |
| 369 | #define CX25821_INFO(fmt, args...) \ |
| 370 | pr_info("(%d): " fmt, dev->board, ##args) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 371 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 372 | extern int cx25821_i2c_register(struct cx25821_i2c *bus); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 373 | extern int cx25821_i2c_read(struct cx25821_i2c *bus, u16 reg_addr, int *value); |
| 374 | extern int cx25821_i2c_write(struct cx25821_i2c *bus, u16 reg_addr, int value); |
| 375 | extern int cx25821_i2c_unregister(struct cx25821_i2c *bus); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 376 | extern void cx25821_gpio_init(struct cx25821_dev *dev); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 377 | extern void cx25821_set_gpiopin_direction(struct cx25821_dev *dev, |
| 378 | int pin_number, int pin_logic_value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 379 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 380 | extern int medusa_video_init(struct cx25821_dev *dev); |
| 381 | extern int medusa_set_videostandard(struct cx25821_dev *dev); |
| 382 | extern void medusa_set_resolution(struct cx25821_dev *dev, int width, |
| 383 | int decoder_select); |
| 384 | extern int medusa_set_brightness(struct cx25821_dev *dev, int brightness, |
| 385 | int decoder); |
| 386 | extern int medusa_set_contrast(struct cx25821_dev *dev, int contrast, |
| 387 | int decoder); |
| 388 | extern int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder); |
| 389 | extern int medusa_set_saturation(struct cx25821_dev *dev, int saturation, |
| 390 | int decoder); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 391 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 392 | extern int cx25821_sram_channel_setup(struct cx25821_dev *dev, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 393 | const struct sram_channel *ch, unsigned int bpl, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 394 | u32 risc); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 395 | |
Hans Verkuil | 5ede94c | 2014-12-12 10:27:54 -0300 | [diff] [blame] | 396 | extern int cx25821_riscmem_alloc(struct pci_dev *pci, |
| 397 | struct cx25821_riscmem *risc, |
| 398 | unsigned int size); |
| 399 | extern int cx25821_risc_buffer(struct pci_dev *pci, struct cx25821_riscmem *risc, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 400 | struct scatterlist *sglist, |
| 401 | unsigned int top_offset, |
| 402 | unsigned int bottom_offset, |
| 403 | unsigned int bpl, |
| 404 | unsigned int padding, unsigned int lines); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 405 | extern int cx25821_risc_databuffer_audio(struct pci_dev *pci, |
Hans Verkuil | 5ede94c | 2014-12-12 10:27:54 -0300 | [diff] [blame] | 406 | struct cx25821_riscmem *risc, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 407 | struct scatterlist *sglist, |
| 408 | unsigned int bpl, |
| 409 | unsigned int lines, unsigned int lpi); |
Hans Verkuil | b671ae6 | 2014-12-12 10:27:58 -0300 | [diff] [blame] | 410 | extern void cx25821_free_buffer(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 411 | struct cx25821_buffer *buf); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 412 | extern void cx25821_sram_channel_dump(struct cx25821_dev *dev, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 413 | const struct sram_channel *ch); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 414 | extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 415 | const struct sram_channel *ch); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 416 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 417 | extern struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci); |
| 418 | extern void cx25821_print_irqbits(char *name, char *tag, char **strings, |
| 419 | int len, u32 bits, u32 mask); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 420 | extern void cx25821_dev_unregister(struct cx25821_dev *dev); |
| 421 | extern int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 422 | const struct sram_channel *ch, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 423 | unsigned int bpl, u32 risc); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 424 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 425 | extern void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel, |
| 426 | u32 format); |
Hans Verkuil | 95c232a | 2013-04-13 07:41:29 -0300 | [diff] [blame] | 427 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 428 | #endif |