mantis_core.c 5.9 KB
Newer Older
1 2 3
/*
	Mantis PCI bridge driver

4
	Copyright (C) Manu Abraham (abraham.manu@gmail.com)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "mantis_common.h"
#include "mantis_core.h"
23 24
#include "mantis_vp1033.h"
#include "mantis_vp1034.h"
25
#include "mantis_vp1041.h"
26
#include "mantis_vp2033.h"
27
#include "mantis_vp2040.h"
28
#include "mantis_vp3030.h"
29 30 31 32 33 34 35 36 37 38

static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
{
	int err;
	struct i2c_msg msg[] = {
		{
			.addr = 0x50,
			.flags = 0,
			.buf = data,
			.len = 1
39
		}, {
40 41 42 43 44 45
			.addr = 0x50,
			.flags = I2C_M_RD,
			.buf = data,
			.len = length
		},
	};
46 47 48

	err = i2c_transfer(&mantis->adapter, msg, 2);
	if (err < 0) {
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
		dprintk(verbose, MANTIS_ERROR, 1,
			"ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
			err, data[0], data[1]);

		return err;
	}

	return 0;
}

static int write_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
{
	int err;

	struct i2c_msg msg = {
		.addr = 0x50,
		.flags = 0,
		.buf = data,
		.len = length
	};

70 71
	err = i2c_transfer(&mantis->adapter, &msg, 1);
	if (err < 0) {
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
		dprintk(verbose, MANTIS_ERROR, 1,
			"ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >",
			err, length, data[0], data[1]);

		return err;
	}

	return 0;
}

static int get_mac_address(struct mantis_pci *mantis)
{
	int err;

	mantis->mac_address[0] = 0x08;
87 88
	err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6);
	if (err < 0) {
89 90 91 92
		dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");

		return err;
	}
93 94
	dprintk(verbose, MANTIS_ERROR, 0,
		"    MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n",
95 96 97 98 99 100 101
		mantis->mac_address[0], mantis->mac_address[1],
		mantis->mac_address[2],	mantis->mac_address[3],
		mantis->mac_address[4], mantis->mac_address[5]);

	return 0;
}

102 103 104 105 106 107 108 109 110 111 112
#define MANTIS_MODEL_UNKNOWN	"UNKNOWN"
#define MANTIS_DEV_UNKNOWN	"UNKNOWN"

struct mantis_hwconfig unknown_device = {
	.model_name	= MANTIS_MODEL_UNKNOWN,
	.dev_type	= MANTIS_DEV_UNKNOWN,
};

static void mantis_load_config(struct mantis_pci *mantis)
{
	switch (mantis->subsystem_device) {
113
	case MANTIS_VP_1033_DVB_S:	/* VP-1033 */
114 115
		mantis->hwconfig = &vp1033_mantis_config;
		break;
116
	case MANTIS_VP_1034_DVB_S:	/* VP-1034 */
117 118
		mantis->hwconfig = &vp1034_mantis_config;
		break;
119
	case MANTIS_VP_1041_DVB_S2:	/* VP-1041 */
120
	case TECHNISAT_SKYSTAR_HD2:
121 122
		mantis->hwconfig = &vp1041_mantis_config;
		break;
123
	case MANTIS_VP_2033_DVB_C:	/* VP-2033 */
124 125
		mantis->hwconfig = &vp2033_mantis_config;
		break;
126 127
	case MANTIS_VP_2040_DVB_C:	/* VP-2040 */
	case TERRATEC_CINERGY_C_PCI:	/* VP-2040 clone */
128
	case TECHNISAT_CABLESTAR_HD2:
129 130
		mantis->hwconfig = &vp2040_mantis_config;
		break;
131
	case MANTIS_VP_3030_DVB_T:	/* VP-3030 */
132 133 134 135 136 137 138
		mantis->hwconfig = &vp3030_mantis_config;
		break;
	default:
		mantis->hwconfig = &unknown_device;
		break;
	}
}
139 140 141 142 143

int mantis_core_init(struct mantis_pci *mantis)
{
	int err = 0;

144 145 146 147 148 149 150 151 152 153 154 155
	mantis_load_config(mantis);
	dprintk(verbose, MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
		mantis->hwconfig->model_name, mantis->hwconfig->dev_type,
		mantis->pdev->bus->number, PCI_SLOT(mantis->pdev->devfn), PCI_FUNC(mantis->pdev->devfn));
	dprintk(verbose, MANTIS_ERROR, 0, "    Mantis Rev %d [%04x:%04x], ",
		mantis->revision,
		mantis->subsystem_vendor, mantis->subsystem_device);
	dprintk(verbose, MANTIS_ERROR, 0,
		"irq: %d, latency: %d\n    memory: 0x%lx, mmio: 0x%p\n",
		mantis->pdev->irq, mantis->latency,
		mantis->mantis_addr, mantis->mantis_mmio);

156 157
	err = mantis_i2c_init(mantis);
	if (err < 0) {
158 159 160
		dprintk(verbose, MANTIS_ERROR, 1, "Mantis I2C init failed");
		return err;
	}
161 162
	err = get_mac_address(mantis);
	if (err < 0) {
163 164 165
		dprintk(verbose, MANTIS_ERROR, 1, "get MAC address failed");
		return err;
	}
166 167
	err = mantis_dma_init(mantis);
	if (err < 0) {
168 169 170
		dprintk(verbose, MANTIS_ERROR, 1, "Mantis DMA init failed");
		return err;
	}
171 172
	err = mantis_dvb_init(mantis);
	if (err < 0) {
173 174 175
		dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB init failed");
		return err;
	}
176 177
	err = mantis_uart_init(mantis);
	if (err < 0) {
178 179 180
		dprintk(verbose, MANTIS_DEBUG, 1, "Mantis UART init failed");
		return err;
	}
181 182 183 184 185 186 187 188

	return 0;
}

int mantis_core_exit(struct mantis_pci *mantis)
{
	mantis_dma_stop(mantis);
	dprintk(verbose, MANTIS_ERROR, 1, "DMA engine stopping");
189 190 191 192

	mantis_uart_exit(mantis);
	dprintk(verbose, MANTIS_ERROR, 1, "UART exit failed");

193 194 195 196 197 198 199 200 201 202
	if (mantis_dma_exit(mantis) < 0)
		dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed");
	if (mantis_dvb_exit(mantis) < 0)
		dprintk(verbose, MANTIS_ERROR, 1, "DVB exit failed");
	if (mantis_i2c_exit(mantis) < 0)
		dprintk(verbose, MANTIS_ERROR, 1, "I2C adapter delete.. failed");

	return 0;
}

203
/* Turn the given bit on or off. */
204 205
void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
{
206
	u32 cur;
207

208
	cur = mmread(MANTIS_GPIF_ADDR);
209
	if (value)
210
		mantis->gpio_status = cur | (1 << bitpos);
211
	else
212
		mantis->gpio_status = cur & (~(1 << bitpos));
213

214
	mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
215 216 217 218
	mmwrite(0x00, MANTIS_GPIF_DOUT);
	udelay(100);
}

219
/* direction = 0 , no CI passthrough ; 1 , CI passthrough */
220 221 222 223 224 225
void mantis_set_direction(struct mantis_pci *mantis, int direction)
{
	u32 reg;

	reg = mmread(0x28);
	dprintk(verbose, MANTIS_DEBUG, 1, "TS direction setup");
226 227
	if (direction == 0x01) {
		/* to CI */
228 229 230 231 232 233 234 235 236 237 238
		reg |= 0x04;
		mmwrite(reg, 0x28);
		reg &= 0xff - 0x04;
		mmwrite(reg, 0x28);
	} else {
		reg &= 0xff - 0x04;
		mmwrite(reg, 0x28);
		reg |= 0x04;
		mmwrite(reg, 0x28);
	}
}