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"
23 #include "mantis_vp1033.h"
24 #include "mantis_vp1034.h"
25 #include "mantis_vp2033.h"
26 #include "mantis_vp3030.h"
28 static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
31 struct i2c_msg msg[] = {
44 if ((err = i2c_transfer(&mantis->adapter, msg, 2)) < 0) {
45 dprintk(verbose, MANTIS_ERROR, 1,
46 "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
47 err, data[0], data[1]);
55 static int write_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
59 struct i2c_msg msg = {
66 if ((err = i2c_transfer(&mantis->adapter, &msg, 1)) < 0) {
67 dprintk(verbose, MANTIS_ERROR, 1,
68 "ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >",
69 err, length, data[0], data[1]);
77 static int get_mac_address(struct mantis_pci *mantis)
81 mantis->mac_address[0] = 0x08;
82 if ((err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6)) < 0) {
83 dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");
87 dprintk(verbose, MANTIS_ERROR, 0,
88 " MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n",
89 mantis->mac_address[0], mantis->mac_address[1],
90 mantis->mac_address[2], mantis->mac_address[3],
91 mantis->mac_address[4], mantis->mac_address[5]);
96 #define MANTIS_MODEL_UNKNOWN "UNKNOWN"
97 #define MANTIS_DEV_UNKNOWN "UNKNOWN"
99 struct mantis_hwconfig unknown_device = {
100 .model_name = MANTIS_MODEL_UNKNOWN,
101 .dev_type = MANTIS_DEV_UNKNOWN,
104 static void mantis_load_config(struct mantis_pci *mantis)
106 switch (mantis->subsystem_device) {
107 case MANTIS_VP_1033_DVB_S: // VP-1033
108 mantis->hwconfig = &vp1033_mantis_config;
110 case MANTIS_VP_1034_DVB_S: // VP-1034
111 mantis->hwconfig = &vp1034_mantis_config;
113 case MANTIS_VP_2033_DVB_C: // VP-2033
114 mantis->hwconfig = &vp2033_mantis_config;
116 case MANTIS_VP_3030_DVB_T: // VP-3030
117 mantis->hwconfig = &vp3030_mantis_config;
120 mantis->hwconfig = &unknown_device;
125 int mantis_core_init(struct mantis_pci *mantis)
129 mantis_load_config(mantis);
130 dprintk(verbose, MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
131 mantis->hwconfig->model_name, mantis->hwconfig->dev_type,
132 mantis->pdev->bus->number, PCI_SLOT(mantis->pdev->devfn), PCI_FUNC(mantis->pdev->devfn));
133 dprintk(verbose, MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
135 mantis->subsystem_vendor, mantis->subsystem_device);
136 dprintk(verbose, MANTIS_ERROR, 0,
137 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
138 mantis->pdev->irq, mantis->latency,
139 mantis->mantis_addr, mantis->mantis_mmio);
141 if ((err = mantis_i2c_init(mantis)) < 0) {
142 dprintk(verbose, MANTIS_ERROR, 1, "Mantis I2C init failed");
145 if ((err = get_mac_address(mantis)) < 0) {
146 dprintk(verbose, MANTIS_ERROR, 1, "get MAC address failed");
149 if ((err = mantis_dma_init(mantis)) < 0) {
150 dprintk(verbose, MANTIS_ERROR, 1, "Mantis DMA init failed");
153 if ((err = mantis_dvb_init(mantis)) < 0) {
154 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB init failed");
161 int mantis_core_exit(struct mantis_pci *mantis)
163 mantis_dma_stop(mantis);
164 dprintk(verbose, MANTIS_ERROR, 1, "DMA engine stopping");
165 if (mantis_dma_exit(mantis) < 0)
166 dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed");
167 if (mantis_dvb_exit(mantis) < 0)
168 dprintk(verbose, MANTIS_ERROR, 1, "DVB exit failed");
169 if (mantis_i2c_exit(mantis) < 0)
170 dprintk(verbose, MANTIS_ERROR, 1, "I2C adapter delete.. failed");
175 // Turn the given bit on or off.
176 void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
180 currVal = mmread(MANTIS_GPIF_ADDR);
183 newVal = currVal | (1 << bitpos);
185 newVal = currVal & (~(1 << bitpos));
187 mmwrite(newVal, MANTIS_GPIF_ADDR);
188 mmwrite(0x00, MANTIS_GPIF_DOUT);
192 //direction = 0 , no CI passthrough ; 1 , CI passthrough
193 void mantis_set_direction(struct mantis_pci *mantis, int direction)
198 dprintk(verbose, MANTIS_DEBUG, 1, "TS direction setup");
199 if (direction == 0x01) { //to CI