Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / media / pci / mantis / mantis_core.c
blobf303f68d4ef20400a55651ec80610de97f5fee2b
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 Mantis PCI bridge driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
7 */
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)
20 int err;
21 struct i2c_msg msg[] = {
23 .addr = 0x50,
24 .flags = 0,
25 .buf = data,
26 .len = 1
27 }, {
28 .addr = 0x50,
29 .flags = I2C_M_RD,
30 .buf = data,
31 .len = length
35 err = i2c_transfer(&mantis->adapter, msg, 2);
36 if (err < 0) {
37 dprintk(verbose, MANTIS_ERROR, 1,
38 "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
39 err, data[0], data[1]);
41 return err;
44 return 0;
47 static int get_mac_address(struct mantis_pci *mantis)
49 int err;
51 mantis->mac_address[0] = 0x08;
52 err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6);
53 if (err < 0) {
54 dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");
56 return err;
58 dprintk(verbose, MANTIS_ERROR, 0,
59 " MAC Address=[%pM]\n", mantis->mac_address);
61 return 0;
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;
77 break;
78 case MANTIS_VP_1034_DVB_S: /* VP-1034 */
79 mantis->hwconfig = &vp1034_mantis_config;
80 break;
81 case MANTIS_VP_1041_DVB_S2: /* VP-1041 */
82 case TECHNISAT_SKYSTAR_HD2:
83 mantis->hwconfig = &vp1041_mantis_config;
84 break;
85 case MANTIS_VP_2033_DVB_C: /* VP-2033 */
86 mantis->hwconfig = &vp2033_mantis_config;
87 break;
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;
92 break;
93 case MANTIS_VP_3030_DVB_T: /* VP-3030 */
94 mantis->hwconfig = &vp3030_mantis_config;
95 break;
96 default:
97 mantis->hwconfig = &unknown_device;
98 break;
102 int mantis_core_init(struct mantis_pci *mantis)
104 int err = 0;
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], ",
111 mantis->revision,
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);
119 if (err < 0) {
120 dprintk(verbose, MANTIS_ERROR, 1, "Mantis I2C init failed");
121 return err;
123 err = get_mac_address(mantis);
124 if (err < 0) {
125 dprintk(verbose, MANTIS_ERROR, 1, "get MAC address failed");
126 return err;
128 err = mantis_dma_init(mantis);
129 if (err < 0) {
130 dprintk(verbose, MANTIS_ERROR, 1, "Mantis DMA init failed");
131 return err;
133 err = mantis_dvb_init(mantis);
134 if (err < 0) {
135 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB init failed");
136 return err;
138 err = mantis_uart_init(mantis);
139 if (err < 0) {
140 dprintk(verbose, MANTIS_DEBUG, 1, "Mantis UART init failed");
141 return err;
144 return 0;
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");
162 return 0;
165 /* Turn the given bit on or off. */
166 void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
168 u32 cur;
170 cur = mmread(MANTIS_GPIF_ADDR);
171 if (value)
172 mantis->gpio_status = cur | (1 << bitpos);
173 else
174 mantis->gpio_status = cur & (~(1 << bitpos));
176 mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
177 mmwrite(0x00, MANTIS_GPIF_DOUT);
178 udelay(100);
181 /* direction = 0 , no CI passthrough ; 1 , CI passthrough */
182 void mantis_set_direction(struct mantis_pci *mantis, int direction)
184 u32 reg;
186 reg = mmread(0x28);
187 dprintk(verbose, MANTIS_DEBUG, 1, "TS direction setup");
188 if (direction == 0x01) {
189 /* to CI */
190 reg |= 0x04;
191 mmwrite(reg, 0x28);
192 reg &= 0xff - 0x04;
193 mmwrite(reg, 0x28);
194 } else {
195 reg &= 0xff - 0x04;
196 mmwrite(reg, 0x28);
197 reg |= 0x04;
198 mmwrite(reg, 0x28);