2019-05-20 01:19:02 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-12-02 17:57:10 -07:00
|
|
|
/*
|
|
|
|
Mantis PCI bridge driver
|
|
|
|
|
2009-12-15 05:13:49 -07:00
|
|
|
Copyright (C) Manu Abraham (abraham.manu@gmail.com)
|
2009-12-02 17:57:10 -07:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mantis_common.h"
|
|
|
|
#include "mantis_core.h"
|
2009-12-02 18:07:24 -07:00
|
|
|
#include "mantis_vp1033.h"
|
|
|
|
#include "mantis_vp1034.h"
|
2009-12-04 00:43:04 -07:00
|
|
|
#include "mantis_vp1041.h"
|
2009-12-02 18:07:24 -07:00
|
|
|
#include "mantis_vp2033.h"
|
2009-12-04 00:42:22 -07:00
|
|
|
#include "mantis_vp2040.h"
|
2009-12-02 18:07:24 -07:00
|
|
|
#include "mantis_vp3030.h"
|
2009-12-02 17:57:10 -07:00
|
|
|
|
|
|
|
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
|
2009-12-15 04:47:21 -07:00
|
|
|
}, {
|
2009-12-02 17:57:10 -07:00
|
|
|
.addr = 0x50,
|
|
|
|
.flags = I2C_M_RD,
|
|
|
|
.buf = data,
|
|
|
|
.len = length
|
|
|
|
},
|
|
|
|
};
|
2009-12-15 04:47:21 -07:00
|
|
|
|
|
|
|
err = i2c_transfer(&mantis->adapter, msg, 2);
|
|
|
|
if (err < 0) {
|
2009-12-02 17:57:10 -07:00
|
|
|
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 get_mac_address(struct mantis_pci *mantis)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mantis->mac_address[0] = 0x08;
|
2009-12-15 04:47:21 -07:00
|
|
|
err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6);
|
|
|
|
if (err < 0) {
|
2009-12-02 17:57:10 -07:00
|
|
|
dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-12-02 18:07:24 -07:00
|
|
|
dprintk(verbose, MANTIS_ERROR, 0,
|
2010-09-11 11:33:27 -06:00
|
|
|
" MAC Address=[%pM]\n", mantis->mac_address);
|
2009-12-02 17:57:10 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-02 18:07:24 -07:00
|
|
|
#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) {
|
2009-12-15 04:47:21 -07:00
|
|
|
case MANTIS_VP_1033_DVB_S: /* VP-1033 */
|
2009-12-02 18:07:24 -07:00
|
|
|
mantis->hwconfig = &vp1033_mantis_config;
|
|
|
|
break;
|
2009-12-15 04:47:21 -07:00
|
|
|
case MANTIS_VP_1034_DVB_S: /* VP-1034 */
|
2009-12-02 18:07:24 -07:00
|
|
|
mantis->hwconfig = &vp1034_mantis_config;
|
|
|
|
break;
|
2009-12-15 04:47:21 -07:00
|
|
|
case MANTIS_VP_1041_DVB_S2: /* VP-1041 */
|
2009-12-04 00:47:30 -07:00
|
|
|
case TECHNISAT_SKYSTAR_HD2:
|
2009-12-04 00:43:04 -07:00
|
|
|
mantis->hwconfig = &vp1041_mantis_config;
|
|
|
|
break;
|
2009-12-15 04:47:21 -07:00
|
|
|
case MANTIS_VP_2033_DVB_C: /* VP-2033 */
|
2009-12-02 18:07:24 -07:00
|
|
|
mantis->hwconfig = &vp2033_mantis_config;
|
|
|
|
break;
|
2009-12-15 04:47:21 -07:00
|
|
|
case MANTIS_VP_2040_DVB_C: /* VP-2040 */
|
2012-05-09 04:23:14 -06:00
|
|
|
case CINERGY_C: /* VP-2040 clone */
|
2009-12-04 01:32:30 -07:00
|
|
|
case TECHNISAT_CABLESTAR_HD2:
|
2009-12-04 00:42:22 -07:00
|
|
|
mantis->hwconfig = &vp2040_mantis_config;
|
|
|
|
break;
|
2009-12-15 04:47:21 -07:00
|
|
|
case MANTIS_VP_3030_DVB_T: /* VP-3030 */
|
2009-12-02 18:07:24 -07:00
|
|
|
mantis->hwconfig = &vp3030_mantis_config;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mantis->hwconfig = &unknown_device;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-12-02 17:57:10 -07:00
|
|
|
|
|
|
|
int mantis_core_init(struct mantis_pci *mantis)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2009-12-02 18:07:24 -07:00
|
|
|
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);
|
|
|
|
|
2009-12-15 04:47:21 -07:00
|
|
|
err = mantis_i2c_init(mantis);
|
|
|
|
if (err < 0) {
|
2009-12-02 17:57:10 -07:00
|
|
|
dprintk(verbose, MANTIS_ERROR, 1, "Mantis I2C init failed");
|
|
|
|
return err;
|
|
|
|
}
|
2009-12-15 04:47:21 -07:00
|
|
|
err = get_mac_address(mantis);
|
|
|
|
if (err < 0) {
|
2009-12-02 17:57:10 -07:00
|
|
|
dprintk(verbose, MANTIS_ERROR, 1, "get MAC address failed");
|
|
|
|
return err;
|
|
|
|
}
|
2009-12-15 04:47:21 -07:00
|
|
|
err = mantis_dma_init(mantis);
|
|
|
|
if (err < 0) {
|
2009-12-02 17:57:10 -07:00
|
|
|
dprintk(verbose, MANTIS_ERROR, 1, "Mantis DMA init failed");
|
|
|
|
return err;
|
|
|
|
}
|
2009-12-15 04:47:21 -07:00
|
|
|
err = mantis_dvb_init(mantis);
|
|
|
|
if (err < 0) {
|
2009-12-02 17:57:10 -07:00
|
|
|
dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB init failed");
|
|
|
|
return err;
|
|
|
|
}
|
2009-12-15 04:47:21 -07:00
|
|
|
err = mantis_uart_init(mantis);
|
|
|
|
if (err < 0) {
|
2009-12-04 01:39:57 -07:00
|
|
|
dprintk(verbose, MANTIS_DEBUG, 1, "Mantis UART init failed");
|
|
|
|
return err;
|
|
|
|
}
|
2009-12-02 17:57:10 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mantis_core_exit(struct mantis_pci *mantis)
|
|
|
|
{
|
|
|
|
mantis_dma_stop(mantis);
|
|
|
|
dprintk(verbose, MANTIS_ERROR, 1, "DMA engine stopping");
|
2009-12-04 01:39:57 -07:00
|
|
|
|
|
|
|
mantis_uart_exit(mantis);
|
|
|
|
dprintk(verbose, MANTIS_ERROR, 1, "UART exit failed");
|
|
|
|
|
2009-12-02 17:57:10 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-15 04:47:21 -07:00
|
|
|
/* Turn the given bit on or off. */
|
2009-12-02 17:57:10 -07:00
|
|
|
void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
|
|
|
|
{
|
2009-12-04 01:15:38 -07:00
|
|
|
u32 cur;
|
2009-12-02 17:57:10 -07:00
|
|
|
|
2009-12-04 01:15:38 -07:00
|
|
|
cur = mmread(MANTIS_GPIF_ADDR);
|
2009-12-02 17:57:10 -07:00
|
|
|
if (value)
|
2009-12-04 01:15:38 -07:00
|
|
|
mantis->gpio_status = cur | (1 << bitpos);
|
2009-12-02 17:57:10 -07:00
|
|
|
else
|
2009-12-04 01:15:38 -07:00
|
|
|
mantis->gpio_status = cur & (~(1 << bitpos));
|
2009-12-02 17:57:10 -07:00
|
|
|
|
2009-12-04 01:15:38 -07:00
|
|
|
mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
|
2009-12-02 17:57:10 -07:00
|
|
|
mmwrite(0x00, MANTIS_GPIF_DOUT);
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
2009-12-15 04:47:21 -07:00
|
|
|
/* direction = 0 , no CI passthrough ; 1 , CI passthrough */
|
2009-12-02 17:57:10 -07:00
|
|
|
void mantis_set_direction(struct mantis_pci *mantis, int direction)
|
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
reg = mmread(0x28);
|
|
|
|
dprintk(verbose, MANTIS_DEBUG, 1, "TS direction setup");
|
2009-12-15 04:47:21 -07:00
|
|
|
if (direction == 0x01) {
|
|
|
|
/* to CI */
|
2009-12-02 17:57:10 -07:00
|
|
|
reg |= 0x04;
|
|
|
|
mmwrite(reg, 0x28);
|
|
|
|
reg &= 0xff - 0x04;
|
|
|
|
mmwrite(reg, 0x28);
|
|
|
|
} else {
|
|
|
|
reg &= 0xff - 0x04;
|
|
|
|
mmwrite(reg, 0x28);
|
|
|
|
reg |= 0x04;
|
|
|
|
mmwrite(reg, 0x28);
|
|
|
|
}
|
|
|
|
}
|