2 Mantis PCI bridge driver
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
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.
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.
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.
21 #include "mantis_common.h"
22 #include "mantis_core.h"
25 static int read_eeprom_byte(struct mantis_pci
*mantis
, u8
*data
, u8 length
)
28 struct i2c_msg msg
[] = {
41 if ((err
= i2c_transfer(&mantis
->adapter
, msg
, 2)) < 0) {
42 dprintk(verbose
, MANTIS_ERROR
, 1,
43 "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
44 err
, data
[0], data
[1]);
48 msleep_interruptible(2);
53 static int write_eeprom_byte(struct mantis_pci
*mantis
, u8
*data
, u8 length
)
57 struct i2c_msg msg
= {
64 if ((err
= i2c_transfer(&mantis
->adapter
, &msg
, 1)) < 0) {
65 dprintk(verbose
, MANTIS_ERROR
, 1,
66 "ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >",
67 err
, length
, data
[0], data
[1]);
75 static int get_subdevice_id(struct mantis_pci
*mantis
)
78 static u8 sub_device_id
[2];
80 mantis
->sub_device_id
= 0;
81 sub_device_id
[0] = 0xfc;
82 if ((err
= read_eeprom_byte(mantis
, &sub_device_id
[0], 2)) < 0) {
83 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis EEPROM read error");
86 mantis
->sub_device_id
= (sub_device_id
[0] << 8) | sub_device_id
[1];
87 dprintk(verbose
, MANTIS_ERROR
, 1, "Sub Device ID=[0x%04x]",
88 mantis
->sub_device_id
);
93 static int get_subvendor_id(struct mantis_pci
*mantis
)
96 static u8 sub_vendor_id
[2];
98 mantis
->sub_vendor_id
= 0;
99 sub_vendor_id
[0] = 0xfe;
100 if ((err
= read_eeprom_byte(mantis
, &sub_vendor_id
[0], 2)) < 0) {
101 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis EEPROM read error");
104 mantis
->sub_vendor_id
= (sub_vendor_id
[0] << 8) | sub_vendor_id
[1];
105 dprintk(verbose
, MANTIS_ERROR
, 1, "Sub Vendor ID=[0x%04x]",
106 mantis
->sub_vendor_id
);
111 static int get_mac_address(struct mantis_pci
*mantis
)
115 mantis
->mac_address
[0] = 0x08;
116 if ((err
= read_eeprom_byte(mantis
, &mantis
->mac_address
[0], 6)) < 0) {
117 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis EEPROM read error");
121 dprintk(verbose
, MANTIS_ERROR
, 1,
122 "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
123 mantis
->mac_address
[0], mantis
->mac_address
[1],
124 mantis
->mac_address
[2], mantis
->mac_address
[3],
125 mantis
->mac_address
[4], mantis
->mac_address
[5]);
131 int mantis_core_init(struct mantis_pci
*mantis
)
135 if ((err
= mantis_i2c_init(mantis
)) < 0) {
136 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis I2C init failed");
139 if ((err
= get_mac_address(mantis
)) < 0) {
140 dprintk(verbose
, MANTIS_ERROR
, 1, "get MAC address failed");
143 if ((err
= get_subvendor_id(mantis
)) < 0) {
144 dprintk(verbose
, MANTIS_ERROR
, 1, "get Sub vendor ID failed");
147 if ((err
= get_subdevice_id(mantis
)) < 0) {
148 dprintk(verbose
, MANTIS_ERROR
, 1, "get Sub device ID failed");
151 if ((err
= mantis_dma_init(mantis
)) < 0) {
152 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis DMA init failed");
155 if ((err
= mantis_dvb_init(mantis
)) < 0) {
156 dprintk(verbose
, MANTIS_DEBUG
, 1, "Mantis DVB init failed");
163 int mantis_core_exit(struct mantis_pci
*mantis
)
166 mantis_dma_stop(mantis
);
167 dprintk(verbose
, MANTIS_ERROR
, 1, "DMA engine stopping");
168 if (mantis_dma_exit(mantis
) < 0)
169 dprintk(verbose
, MANTIS_ERROR
, 1, "DMA exit failed");
170 if (mantis_dvb_exit(mantis
) < 0)
171 dprintk(verbose
, MANTIS_ERROR
, 1, "DVB exit failed");
172 if (mantis_i2c_exit(mantis
) < 0)
173 dprintk(verbose
, MANTIS_ERROR
, 1, "I2C adapter delete.. failed");
178 void gpio_set_bits(struct mantis_pci
*mantis
, u32 bitpos
, u8 value
)
187 reg
= (value
<< bitpos
);
189 mmwrite(mmread(MANTIS_GPIF_ADDR
) | reg
, MANTIS_GPIF_ADDR
);
190 mmwrite(0x00, MANTIS_GPIF_DOUT
);
192 mmwrite(mmread(MANTIS_GPIF_ADDR
) | reg
, MANTIS_GPIF_ADDR
);
193 mmwrite(0x00, MANTIS_GPIF_DOUT
);
197 //direction = 0 , no CI passthrough ; 1 , CI passthrough
198 void mantis_set_direction(struct mantis_pci
*mantis
, int direction
)
203 dprintk(verbose
, MANTIS_DEBUG
, 1, "TS direction setup");
204 if (direction
== 0x01) { //to CI