6b9f92b4ab398f06e709ce2cf888384e3b2be69d
[firefly-linux-kernel-4.4.55.git] / drivers / media / dvb / mantis / mantis_common.h
1 /*
2         Mantis PCI bridge driver
3
4         Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.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         GNU General Public License for more details.
15
16         You should have received a copy of the GNU General Public License
17         along with this program; if not, write to the Free Software
18         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef __MANTIS_COMMON_H
22 #define __MANTIS_COMMON_H
23
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/kernel.h>
27 #include <linux/pci.h>
28 #include <linux/mutex.h>
29
30 #include "dvbdev.h"
31 #include "dvb_demux.h"
32 #include "dmxdev.h"
33 #include "dvb_frontend.h"
34 #include "dvb_net.h"
35 #include <linux/i2c.h>
36 #include "mantis_reg.h"
37
38 #include "mantis_link.h"
39
40 #define MANTIS_ERROR            0
41 #define MANTIS_NOTICE           1
42 #define MANTIS_INFO             2
43 #define MANTIS_DEBUG            3
44
45 #define dprintk(x, y, z, format, arg...) do {                                                           \
46         if (z) {                                                                                        \
47                 if      ((x > MANTIS_ERROR) && (x > y))                                                 \
48                         printk(KERN_ERR "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);      \
49                 else if ((x > MANTIS_NOTICE) && (x > y))                                                \
50                         printk(KERN_NOTICE "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);   \
51                 else if ((x > MANTIS_INFO) && (x > y))                                                  \
52                         printk(KERN_INFO "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);     \
53                 else if ((x > MANTIS_DEBUG) && (x > y))                                                 \
54                         printk(KERN_DEBUG "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);    \
55         } else {                                                                                        \
56                 if (x > y)                                                                              \
57                         printk(format , ##arg);                                                         \
58         }                                                                                               \
59 } while(0)
60
61 #define mwrite(dat, addr)       writel((dat), addr)
62 #define mread(addr)             readl(addr)
63
64 #define mmwrite(dat, addr)      mwrite((dat), (mantis->mantis_mmio + (addr)))
65 #define mmread(addr)            mread(mantis->mantis_mmio + (addr))
66 #define mmand(dat, addr)        mmwrite((dat) & mmread(addr), addr)
67 #define mmor(dat, addr)         mmwrite((dat) | mmread(addr), addr)
68 #define mmaor(dat, addr)        mmwrite((dat) | ((mask) & mmread(addr)), addr)
69
70 #define MANTIS_TS_188           0
71 #define MANTIS_TS_204           1
72
73 struct mantis_hwconfig {
74         char                    *model_name;
75         char                    *dev_type;
76         u32                     ts_size;
77 };
78
79 struct mantis_pci {
80         unsigned int            verbose;
81
82         /*      PCI stuff               */
83         u16                     vendor_id;
84         u16                     device_id;
85         u16                     subsystem_vendor;
86         u16                     subsystem_device;
87
88         u8                      latency;
89
90         struct pci_dev          *pdev;
91
92         unsigned long           mantis_addr;
93         volatile void __iomem   *mantis_mmio;
94
95         u8                      irq;
96         u8                      revision;
97
98         unsigned int            num;
99
100         /*      RISC Core               */
101         u32                     finished_block;
102         u32                     last_block;
103         u32                     line_bytes;
104         u32                     line_count;
105         u32                     risc_pos;
106         u8                      *buf_cpu;
107         dma_addr_t              buf_dma;
108         u32                     *risc_cpu;
109         dma_addr_t              risc_dma;
110
111         struct tasklet_struct   tasklet;
112
113         struct i2c_adapter      adapter;
114         int                     i2c_rc;
115         wait_queue_head_t       i2c_wq;
116         struct mutex            i2c_lock;
117
118         /*      DVB stuff               */
119         struct dvb_adapter      dvb_adapter;
120         struct dvb_frontend     *fe;
121         struct dvb_demux        demux;
122         struct dmxdev           dmxdev;
123         struct dmx_frontend     fe_hw;
124         struct dmx_frontend     fe_mem;
125         struct dvb_net          dvbnet;
126
127         u8                      feeds;
128
129         struct mantis_hwconfig  *hwconfig;
130
131         u32                     mantis_int_stat;
132         u32                     mantis_int_mask;
133
134         /*      board specific          */
135         u8                      mac_address[8];
136         u32                     sub_vendor_id;
137         u32                     sub_device_id;
138
139          /*     A12 A13 A14             */
140         u32                     gpio_status;
141
142         u32                     gpif_status;
143
144         struct mantis_ca        *mantis_ca;
145 };
146
147 #define MANTIS_HIF_STATUS       (mantis->gpio_status)
148
149 extern unsigned int verbose;
150 extern unsigned int devs;
151 extern unsigned int i2c;
152 extern int mantis_dvb_init(struct mantis_pci *mantis);
153 extern int mantis_frontend_init(struct mantis_pci *mantis);
154 extern int mantis_dvb_exit(struct mantis_pci *mantis);
155 extern void mantis_dma_xfer(unsigned long data);
156 extern void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value);
157
158 extern void mantis_set_direction(struct mantis_pci *mantis, int direction);
159
160 extern int mantis_ca_init(struct mantis_pci *mantis);
161 extern void mantis_ca_exit(struct mantis_pci *mantis);
162
163
164 #endif //__MANTIS_COMMON_H