1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Mantis PCI bridge driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
9 #include "mantis_common.h"
10 #include "mantis_core.h"
11 #include "mantis_vp1033.h"
12 #include "mantis_vp1034.h"
13 #include "mantis_vp1041.h"
14 #include "mantis_vp2033.h"
15 #include "mantis_vp2040.h"
16 #include "mantis_vp3030.h"
18 static int read_eeprom_byte(struct mantis_pci
*mantis
, u8
*data
, u8 length
)
21 struct i2c_msg msg
[] = {
35 err
= i2c_transfer(&mantis
->adapter
, msg
, 2);
37 dprintk(verbose
, MANTIS_ERROR
, 1,
38 "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
39 err
, data
[0], data
[1]);
47 static int get_mac_address(struct mantis_pci
*mantis
)
51 mantis
->mac_address
[0] = 0x08;
52 err
= read_eeprom_byte(mantis
, &mantis
->mac_address
[0], 6);
54 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis EEPROM read error");
58 dprintk(verbose
, MANTIS_ERROR
, 0,
59 " MAC Address=[%pM]\n", mantis
->mac_address
);
64 #define MANTIS_MODEL_UNKNOWN "UNKNOWN"
65 #define MANTIS_DEV_UNKNOWN "UNKNOWN"
67 struct mantis_hwconfig unknown_device
= {
68 .model_name
= MANTIS_MODEL_UNKNOWN
,
69 .dev_type
= MANTIS_DEV_UNKNOWN
,
72 static void mantis_load_config(struct mantis_pci
*mantis
)
74 switch (mantis
->subsystem_device
) {
75 case MANTIS_VP_1033_DVB_S
: /* VP-1033 */
76 mantis
->hwconfig
= &vp1033_mantis_config
;
78 case MANTIS_VP_1034_DVB_S
: /* VP-1034 */
79 mantis
->hwconfig
= &vp1034_mantis_config
;
81 case MANTIS_VP_1041_DVB_S2
: /* VP-1041 */
82 case TECHNISAT_SKYSTAR_HD2
:
83 mantis
->hwconfig
= &vp1041_mantis_config
;
85 case MANTIS_VP_2033_DVB_C
: /* VP-2033 */
86 mantis
->hwconfig
= &vp2033_mantis_config
;
88 case MANTIS_VP_2040_DVB_C
: /* VP-2040 */
89 case CINERGY_C
: /* VP-2040 clone */
90 case TECHNISAT_CABLESTAR_HD2
:
91 mantis
->hwconfig
= &vp2040_mantis_config
;
93 case MANTIS_VP_3030_DVB_T
: /* VP-3030 */
94 mantis
->hwconfig
= &vp3030_mantis_config
;
97 mantis
->hwconfig
= &unknown_device
;
102 int mantis_core_init(struct mantis_pci
*mantis
)
106 mantis_load_config(mantis
);
107 dprintk(verbose
, MANTIS_ERROR
, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
108 mantis
->hwconfig
->model_name
, mantis
->hwconfig
->dev_type
,
109 mantis
->pdev
->bus
->number
, PCI_SLOT(mantis
->pdev
->devfn
), PCI_FUNC(mantis
->pdev
->devfn
));
110 dprintk(verbose
, MANTIS_ERROR
, 0, " Mantis Rev %d [%04x:%04x], ",
112 mantis
->subsystem_vendor
, mantis
->subsystem_device
);
113 dprintk(verbose
, MANTIS_ERROR
, 0,
114 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
115 mantis
->pdev
->irq
, mantis
->latency
,
116 mantis
->mantis_addr
, mantis
->mantis_mmio
);
118 err
= mantis_i2c_init(mantis
);
120 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis I2C init failed");
123 err
= get_mac_address(mantis
);
125 dprintk(verbose
, MANTIS_ERROR
, 1, "get MAC address failed");
128 err
= mantis_dma_init(mantis
);
130 dprintk(verbose
, MANTIS_ERROR
, 1, "Mantis DMA init failed");
133 err
= mantis_dvb_init(mantis
);
135 dprintk(verbose
, MANTIS_DEBUG
, 1, "Mantis DVB init failed");
138 err
= mantis_uart_init(mantis
);
140 dprintk(verbose
, MANTIS_DEBUG
, 1, "Mantis UART init failed");
147 int mantis_core_exit(struct mantis_pci
*mantis
)
149 mantis_dma_stop(mantis
);
150 dprintk(verbose
, MANTIS_ERROR
, 1, "DMA engine stopping");
152 mantis_uart_exit(mantis
);
153 dprintk(verbose
, MANTIS_ERROR
, 1, "UART exit failed");
155 if (mantis_dma_exit(mantis
) < 0)
156 dprintk(verbose
, MANTIS_ERROR
, 1, "DMA exit failed");
157 if (mantis_dvb_exit(mantis
) < 0)
158 dprintk(verbose
, MANTIS_ERROR
, 1, "DVB exit failed");
159 if (mantis_i2c_exit(mantis
) < 0)
160 dprintk(verbose
, MANTIS_ERROR
, 1, "I2C adapter delete.. failed");
165 /* Turn the given bit on or off. */
166 void gpio_set_bits(struct mantis_pci
*mantis
, u32 bitpos
, u8 value
)
170 cur
= mmread(MANTIS_GPIF_ADDR
);
172 mantis
->gpio_status
= cur
| (1 << bitpos
);
174 mantis
->gpio_status
= cur
& (~(1 << bitpos
));
176 mmwrite(mantis
->gpio_status
, MANTIS_GPIF_ADDR
);
177 mmwrite(0x00, MANTIS_GPIF_DOUT
);
181 /* direction = 0 , no CI passthrough ; 1 , CI passthrough */
182 void mantis_set_direction(struct mantis_pci
*mantis
, int direction
)
187 dprintk(verbose
, MANTIS_DEBUG
, 1, "TS direction setup");
188 if (direction
== 0x01) {