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 <linux/kernel.h>
10 #include <linux/i2c.h>
12 #include <linux/signal.h>
13 #include <linux/sched.h>
14 #include <linux/interrupt.h>
17 #include <media/dmxdev.h>
18 #include <media/dvbdev.h>
19 #include <media/dvb_demux.h>
20 #include <media/dvb_frontend.h>
21 #include <media/dvb_net.h>
23 #include "mantis_common.h"
24 #include "mantis_reg.h"
25 #include "mantis_ioc.h"
27 static int read_eeprom_bytes(struct mantis_pci
*mantis
, u8 reg
, u8
*data
, u8 length
)
29 struct i2c_adapter
*adapter
= &mantis
->adapter
;
33 struct i2c_msg msg
[] = {
34 { .addr
= 0x50, .flags
= 0, .buf
= &buf
, .len
= 1 },
35 { .addr
= 0x50, .flags
= I2C_M_RD
, .buf
= data
, .len
= length
},
38 err
= i2c_transfer(adapter
, msg
, 2);
40 dprintk(MANTIS_ERROR
, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
41 err
, data
[0], data
[1]);
48 int mantis_get_mac(struct mantis_pci
*mantis
)
53 err
= read_eeprom_bytes(mantis
, 0x08, mac_addr
, 6);
55 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis EEPROM read error <%d>", err
);
60 dprintk(MANTIS_ERROR
, 0, " MAC Address=[%pM]\n", mac_addr
);
64 EXPORT_SYMBOL_GPL(mantis_get_mac
);
66 /* Turn the given bit on or off. */
67 void mantis_gpio_set_bits(struct mantis_pci
*mantis
, u32 bitpos
, u8 value
)
71 dprintk(MANTIS_DEBUG
, 1, "Set Bit <%d> to <%d>", bitpos
, value
);
72 cur
= mmread(MANTIS_GPIF_ADDR
);
74 mantis
->gpio_status
= cur
| (1 << bitpos
);
76 mantis
->gpio_status
= cur
& (~(1 << bitpos
));
78 dprintk(MANTIS_DEBUG
, 1, "GPIO Value <%02x>", mantis
->gpio_status
);
79 mmwrite(mantis
->gpio_status
, MANTIS_GPIF_ADDR
);
80 mmwrite(0x00, MANTIS_GPIF_DOUT
);
82 EXPORT_SYMBOL_GPL(mantis_gpio_set_bits
);
84 int mantis_stream_control(struct mantis_pci
*mantis
, enum mantis_stream_control stream_ctl
)
88 reg
= mmread(MANTIS_CONTROL
);
91 dprintk(MANTIS_DEBUG
, 1, "Set stream to HIF");
92 reg
&= 0xff - MANTIS_BYPASS
;
93 mmwrite(reg
, MANTIS_CONTROL
);
95 mmwrite(reg
, MANTIS_CONTROL
);
99 dprintk(MANTIS_DEBUG
, 1, "Set stream to CAM");
100 reg
|= MANTIS_BYPASS
;
101 mmwrite(reg
, MANTIS_CONTROL
);
102 reg
&= 0xff - MANTIS_BYPASS
;
103 mmwrite(reg
, MANTIS_CONTROL
);
106 dprintk(MANTIS_ERROR
, 1, "Unknown MODE <%02x>", stream_ctl
);
112 EXPORT_SYMBOL_GPL(mantis_stream_control
);